遭遇ASP.NET(C#)Excel导入Dataset的数据值丢失问题(Excel to Dataset混合字段的格式问题)

最近TCAT Survey项目中,Excel数据导入遭遇到了一个问题,从Excel导入的数据中有部分数据丢失。如下图所示,ZIP字段明明设置了是文本格式,但是导入到数据库中去时似乎因为存在格式问题二导致部分数据导入为空,大致是混合字段的格式问题,如何解决?只需要在Excel to Dataset的时候,加一个IMEX=1的字符串,如下图所示,含义是“IMEX = 1; 告诉系统如一个列中有数字和文本 就是“混合”数据列, 那么都作为文本来对待”,OK,这样导入就能正常导入了。

另外一个参数HDR=Yes; 告诉系统表示第一行包含columnnames,而不是数据。

You need to use IMEX attribute, If your excel is 2003, then excel library version is 11.0, but 8.0 should also be fine. Try the below things

Extended Properties='Excel 8.0;IMEX=1'; The single quotes should start after = and end after 1. If this does not work try the below

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:MyExcel.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""

"HDR=Yes;" indicates that the first row contains columnnames, not data.
"IMEX=1;" tells the driver to always read "intermixed" data columns as text

引用通告地址: 点击获取引用地址
标签: 方案 .NET
评论: 0 | 引用: 0 | 阅读: 1480 | 打印 | 打包 | 转发
发表评论
昵 称: 密 码:
网 址: 邮 箱:
验证码: 验证码图片 选 项:
头 像:
内 容:
  • 粗体
  • 斜体
  • 下划线
  • 插入图像
  • 超链接
  • 电子邮件
  • 插入引用