将数据从 Excel 导入到数据集后,数据集中的逗号被删除
我正在使用 Vs 2008。
我们有一个导入 Excel 文件的功能,现在 Excel 文件可以包含带逗号的数字数据。但是,当查看同一数字列的数据集时,逗号被删除。
我一直在使用连接字符串:
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + "_EXCEL_FILE_NAME_" + ";Extended Properties=\"Excel 8.0; IMEX=1; HDR=YES\""
我尝试了扩展属性的所有组合,但没有任何效果对我有用。
我在互联网上搜索过,我了解到这是 Microsoft.jet.oledb 提供商暴露的一种限制。
如果我错了,请纠正我,并为我提供解决此问题的方法。
i am using Vs 2008.
We have one functionality where we import excel file,Now excel file can contain numeric data with comma,.However when look at Dataset for same numeric column Commas are getting removed.
I have been using Connection string :
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + "_EXCEL_FILE_NAME_" + ";Extended Properties=\"Excel 8.0; IMEX=1; HDR=YES\""
i tried all combination of exteneded properties but nothing worked for me.
I have searched on the internet,i have learnt that it is kind of limitation exposed by Microsoft.jet.oledb provider.
Please correct me if i am wrong and provide me a way to get around this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
逗号实际上并不是数据的一部分——它只是在 Excel 中呈现数据时的表示形式!
如果 Excel 中有一个字段是数字数据,但您要求导出时包含逗号,那么您需要将其转换为其他类型,例如使用前导
'
技巧的字符串。The comma is not actually part of the data - it is only in the representation of the data when presented in excel!!
If you have a field in excel that is numeric data, but you require it to have commas when exported, then you need to convert it to some other type, such as a string using the leading
'
trick.问题在于,如果您导入使用逗号作为小数分隔符的小数并将其导入到使用点作为分隔符的系统中,则逗号可能会被解释为千位分隔符。
解决方案可以在这些SO线程中找到:这里和< a href="https://stackoverflow.com/questions/2844810/double-tryparse-input-decimal-separator- Different-than-system-decimal-separato">此处。
导入数据时,您可能需要通过
NumberStyles
和CultureInfo
显式指定数字格式。这些是特定于文化的,如果您不指定格式,可能会默认为您不期望的内容并导致非常数值。The trouble is that if you import a decimal that uses a comma as a decimal separator and import it into a system that uses point as the separator, the comma may be is interpreted as a thousands-separator.
Solutions can be found in these SO threads: Here and here.
When importing the data, you might want to explicitly specify the number formats via
NumberStyles
andCultureInfo
. These are culture specific and, if you do not specify the format, may default to something you did not expect and result in very number values.要解决此问题,使用此功能的每台计算机都需要完成以下操作:
之后您应该不会再有问题...
To solve this issue, every computer where this is used needs to have the following done:
You should have no more issues after that...