你怎么prevent使用C#导入Excel文档时被剥离前导零 [英] How do you prevent leading zeros from being stripped when importing an excel doc using c#

查看:138
本文介绍了你怎么prevent使用C#导入Excel文档时被剥离前导零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够连接并读取Excel文件没有问题。但是Excel猜测的数据类型,并在这个过程中导入具有前导零,你怎么了prevent数据,如拉链codeS时剥离出的前导零?

I'm able to connect to and read an excel file no problem. But when importing data such as zipcodes that have leading zeros, how do you prevent excel from guessing the datatype and in the process stripping out leading zeros?

推荐答案

我相信你必须在你的连接字符串选项设置为强制文本输入,而不是自动检测到它。

I believe you have to set the option in your connect string to force textual import rather than auto-detecting it.

Provider=Microsoft.ACE.OLEDB.12.0;
    Data Source=c:\path\to\myfile.xlsx;
    Extended Properties=\"Excel 12.0 Xml;IMEX=1\";

根据您所安装的版本,你milage可能会有所不同。该IMEX = 1扩展属性告诉Excel来处理混杂的数据为文本。

Your milage may vary depending on the version you have installed. The IMEX=1 extended property tells Excel to treat intermixed data as text.

这篇关于你怎么prevent使用C#导入Excel文档时被剥离前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆