+ templateName + "';Extended Properties = 'Excel 8.0;HDR=YES;IMEX=1;'";

                    excelOleDBConnection 
= new OleDbConnection(connectString);
                    excelOleDBCommand 
= new OleDbCommand("SELECT * FROM [" + sheetName + "$]", excelOleDBConnection);
                    excelOleDBDataAdapter 
= new OleDbDataAdapter(excelOleDBCommand);

                    excelOleDBDataAdapter.Fill(templetData);
                    excelOleDBCommand.Dispose();
                    excelOleDBDataAdapter.Dispose();

 

记得设置 IMEX=1,否则会有可能对默写混合类型的数据读出来是空的情况

 

HDR=Yes/No

可选参数,指定 Excel 表的第一行是否列名,缺省为 Yes,可以在注册表中修改缺省的行为。

IMEX=1

可选参数,将 Excel 表中混合 Intermixed 数据类型的列强制解析为文本

 

HDR=Yes;" indicates that the first row contains columnnames, not data. "HDR=No;" indicates the opposite. 
"IMEX=1;" tells the driver to always read "intermixed" (numbers, dates, strings etc) data columns as text. Note that this option might affect excel sheet write access negative.

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2021-08-14
  • 2022-12-23
  • 2021-09-27
  • 2022-02-04
猜你喜欢
  • 2022-12-23
  • 2021-11-21
  • 2021-11-20
  • 2021-12-12
  • 2022-12-23
  • 2022-01-10
  • 2021-10-19
相关资源
相似解决方案