复制代码 代码如下: string fileExt = Path.GetExtension(excelPath); string conn = ""; if (fileExt == ".xls") { conn = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" + excelPath + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'"
string fileExt = Path.GetExtension(excelPath);
string conn = "";
if (fileExt == ".xls")
{
conn = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" + excelPath + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'";
}
else
{
conn = "Provider = Microsoft.ACE.OLEDB.12.0 ; Data Source =" + excelPath + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1'";
}
03和07、10等版本的引擎不同
03是Microsoft.Jet.OLEDB.4.0
07及以上是Microsoft.ACE.OLEDB.12.0
并且Microsoft.ACE.OLEDB.12.0引擎需要一个文件,下载安装:http://www.microsoft.com/zh-cn/download/details.aspx?id=23734
其实后者可以兼容前者尴尬
参考文章链接:http://blog.csdn.net/Limpire/article/details/2599760