从Excel读数据,有时候会读出空的字符串
2008-09-12 09:57
190 查看
Code
connectString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = '"
+ 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.
connectString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = '"
+ 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.
相关文章推荐
- Excel 筛选数据、根据公式组成字符串
- 用Java JXL实现从excel读出数据转入数据库及例子
- PHPexcel导入excel数据时对行列中的数据进行字符串格式化
- 从EXCEL中读出数据到数据库中
- 关于mybatis读取数据库字段text类型时,读出数据为地址,并不是字符串的问题
- 给定一个一oracle建表的sql语句,解析读出的字符串,将表名、字段名、字段类型数据取出,怎么实现啊?
- 【软件自动化测试-QTP实战技能 9】== 从外部excel中读出数据导入到qtp的data中
- python 从excel中读取数据转换成json字符串
- 从Excel中读出数据并倒入sql2000中
- 使用OLEDB读取不同版本Excel数据的连接字符串设置
- OLEDB方式读取Excel丢失数据、字符串截断的原因和解决方法
- excel中电话记录数据导入到sqlserver,字符串电话或者数字电话为null的解决方案!
- java从数据库中取出数据写到txt或excel,并对字符串操作—取子字符串,删除字符串中某些特殊字符
- 将Excel中读取的科学计数法表示的Double数据转换为对应的字符串
- c#程序调试时,写入/读出数据于Excel处理
- sql server复制数据到excel格式变成字符串
- OLEDB方式操作规则EXCEL的字符串的完整写法(解决标题行和列数据类型不一致的问题)
- 从数据库读出数据到excel完整代码
- 使用OLEDB读取不同版本Excel数据的连接字符串设置
- 使用OLEDB读取不同版本Excel数据的连接字符串设置