在读取Excel时,出现外部表不是预期的格式
来源:互联网 发布:风行电视 软件下载 编辑:程序博客网 时间:2024/06/04 18:49
Excel “External table is not in the expected format.” .
Question:
I'm trying to read an Excel (xlsx) file using the code shown below. I get an "External table is not in the expected format." error unless I have the file already open in Excel. In other words, I have to open the file in Excel first before I can read if from my C# program. The xlsx file is on a share on our network. How can I read the file without having to open it first? Thanks
string sql = "SELECT * FROM [Sheet1$]"; string excelConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathname + ";Extended Properties=/"Excel 8.0;HDR=YES;IMEX=1;/""; using (OleDbDataAdapter adaptor = new OleDbDataAdapter(sql, excelConnection)) { DataSet ds = new DataSet(); adaptor.Fill(ds); }
Answers:
"External table is not in the expected format." typically occurs when trying to use an Excel 2007 file with a connection string that uses: Microsoft.Jet.OLEDB.4.0 and Extended Properties=Excel 8.0
Using the following connection string seems to fix most problems.
public static string path = @"C:/src/RedirectApplication/RedirectApplication/301s.xlsx"; public static string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";
以上出处:http://blog.csdn.net/ldl22847/article/details/6322339
很多人换了2010后,问的最多的问题之一是2003里最经典的ADO中的“provider=Microsoft.Jet.OLEDB.4.0”这句怎么不能用了。
百度一下可以了解到,Microsoft.Jet.OLEDB.4.0是Microsoft Jet引擎,这适用于2003版本(2003之前的我没装,所以也不知道能向下适应到哪个版本),而在2007中,微软对其旗下 Access 与 Excel 的主要文件格式进行修改,并且重命名为 .accdb(Access 2007 数据库文件)与 .xlsx(Excel 2007 文件),因此未被 Microsoft Jet 引擎所支持,不过微软也很快的提出了Microsoft Office 2007 Desktop Drivers: Data Connectivity Components 来支持,目前的解决方法就是把连接字符串中的数据提供者改
为Microsoft.ACE.OLEDB.12.0。
//2003(Microsoft.Jet.Oledb.4.0)
string strConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'", excelFilePath);
//2010(Microsoft.ACE.OLEDB.12.0)
string strConn = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'", excelFilePath);
若是乱码,我这边测试是不会提示这个错误的,可以成功导入。
- 在读取Excel时,出现外部表不是预期的格式
- 操作Excel出现“外部表不是预期的格式”错误
- Excel导入数据出现“外部表不是预期的格式”错误的解决方法
- c#中导入excel至sql server时出现“外部表不是预期格式”
- 导出Excel—外部表不是预期的格式
- 导入excel错误:外部表不是预期的格式 解决方案
- 导入excel错误:外部表不是预期的格式 解决方案
- 导入excel错误:外部表不是预期的格式 解决方案
- 导入excel错误:外部表不是预期的格式 解决方案
- 导入excel错误:外部表不是预期的格式 解决方案
- 导入excel错误:外部表不是预期的格式 解决方案
- 导入excel错误:外部表不是预期的格式 解决方案
- 导入excel错误:外部表不是预期的格式 解决方案
- C#连接Excel提示“外部表不是预期的格式”
- 对于连接Excel时“外部表不是预期的格式”错误的处理
- 对于连接Excel时“外部表不是预期的格式”错误的处理
- EXCEL文档没有打开时,报错误"外部表不是预期的格式。"
- 外部表不是预期的格式错误
- BZOJ 2287 【POJ Challenge】消失之物
- ubuntu下配置samba服务器
- 笔录《编写高质量代码:改善Java程序的151个建议》
- 查找数组里是否包含元素,如果包含,则返回TRUE
- Sicily 会议安排 | 算法期末机考模拟题
- 在读取Excel时,出现外部表不是预期的格式
- 位运算之求整数二进制表示中1的个数
- 198 House Robber
- bootstrap中各类表单的应用
- Java语言高编——面向对象-继承
- artQuickGenericJniTrampoline
- MySQL启动关闭方式总结(Linux系统)
- java组合模式
- iOS NSUserDefaults数据保存报错:Attempt to set a non-property-list object...