"could not find installable isam" 尝试使用 oledb 读取 Excel 文件时出现异常

"could not find installable isam" exception when trying to read an Excel file with oledb

我正在尝试使用 OLEDB 读取 Excel 文件(xlsx 格式)。 尝试打开连接时出现异常 "could not find installable isam".

string conStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+fileName+";Extended Properties='Excel 12.0 XML;';";
OleDbConnection conn=new OleDbConnection(conStr);
conn.Open();

我已经研究了很多,主要是在这里,但是我找到的所有答案都没有解决这个问题。 有什么想法吗?

对于.xlsx,应该是:

StrConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + srcFile + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";";

(注意额外的 Xml 部分,HDR=YES 表示您的文件有 headers,IMEX=1 将所有数据视为文本并重新定位 semi-colon。 .xlsm 和 .xlsb 文件需要不同的连接字符串 - 请参阅 here)