C#读取Excel时报错:External table is not in the expected format.
时间:2010-11-19 来源:leco_lin
其实,这个错误是由于Excel版本的连接字符串引起的错误,
在上一篇日志提到的方法中,excel的连接字符串如下:
public static string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\WorkSpace\MyDocument\Samples2.xlsx;Extended Properties=""Excel 8.0;HDR=YES;""";
用这种方法读取Excel2007时候,必须先在当前电脑上手动打开Excel摆放在那里,然后才能运行程序,显然这不会是我们的需求。
要解决这个问题更改连接字符串的OLEDB和Extended Properties版本即可,如下:
public static string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\WorkSpace\MyDocument\Samples.xlsx;Extended Properties=""Excel 12.0;HDR=YES;""";
相关阅读 更多 +
排行榜 更多 +