【问题标题】:connection provider to read xls files读取 xls 文件的连接提供程序
【发布时间】:2013-07-25 04:06:59
【问题描述】:

我使用下面的连接字符串来读取 xlsx 文件。它工作正常。

connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=\"Excel 8.0;HDR=NO;\"";

下面的读取 xls 文件的连接字符串不起作用

connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Excel 8.0;Extended Properties=HDR=NO;IMEX=1;Data Source=" + fileName + ";";

请更正这一点。提前致谢

【问题讨论】:

  • 第一个是Extended Properties=\"Excel 8.0;HDR=NO;\",第二个是Extended Properties=HDR=NO;IMEX=1;。试试引号。

标签: c# visual-studio excel connection-string


【解决方案1】:
  Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;
  Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";

"HDR=Yes;" 表示第一行包含列名,而不是数据。 "HDR=No;" 表示相反。

"IMEX=1;" 告诉驱动程序始终将“混合”(数字、日期、字符串等)数据列作为文本读取。请注意,此选项可能会影响 Excel 工作表写入访问权限。

SQL 语法“SELECT [Column Name One], [Column Name Two] FROM [Sheet One$]”。 IE。 excel 工作表名称后跟“$”并用“[”“]”括号括起来。

【讨论】:

  • 我试过这个,仍然得到错误,“无法解密文件”。 "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=\"Excel 8.0;HDR=NO;\""
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-01-25
  • 1970-01-01
  • 2014-02-18
  • 1970-01-01
  • 2012-08-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多