復制代碼 代碼如下:
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