您的位置:首页 > 编程语言 > ASP

解决ASP.NET 读取EXCEL 单元格 无法读取 空值 不显示

2012-02-01 10:21 435 查看
读取excel时,某些单元格为空值

当我们用oledb读取excel的时候,如果没有配置imex=1的属性,微软的处理机制是将列转换为同一类型来读取的.例如你在第一行写的数字格式,而第二行写的字符格式,就会出现某些列有值却读不出来.其实问题也很简单,如果知道问题所在的话.属性设置为"imex=1"即可

附以下参考:

string xlsdriver = @"provider=microsoft.jet.oledb.4.0;data source={0};extended properties='excel 8.0;imex=1';";

oledbconnection conn = new oledbconnection(string.format(xlsdriver, filename));

"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.

加上imex=1这个属性,excel单元格的值就会以文本型读取,避免由于数据类型不一致导致某些值读不出来的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: