【发布时间】:2014-08-19 08:25:08
【问题描述】:
我正在开发一个 MVC .Net Web 应用程序,我想从 Excel 文件中读取一些数据。 我正在使用这些连接字符串:
if (fileExtension == ".xlsx")
{
excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"" +
fileLocation + "\";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\"";
}
else if (fileExtension == ".xls")
{
excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
}
读取 .xls 文件效果很好,但尝试读取 .xlsx 文件(在 Excel 2013 中创建)不起作用,给我一个例外:
外部表不是预期的格式。
我一直在尝试我找到的所有可能的连接字符串:
excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"" +
fileLocation + "\";Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1\"";
excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"" +
fileLocation + "\";Extended Properties=\"Excel 12.0;HDR=YES;IMEX=2\"";
excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"" +
fileLocation + "\";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=2\"";
...
...
...
但我无法解决这个问题。
谢谢!
【问题讨论】:
标签: c# excel connection-string oledb