从Excel中的净进口时科学记数法 [英] Scientific notation when importing from Excel in .Net

查看:127
本文介绍了从Excel中的净进口时科学记数法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#/。就业网,从Excel导入数据,然后进行处理。我们的客户脱落的文件,我们处理这些(重要,因为我没有对原始文件的任何控件)。

I have a C#/.Net job that imports data from Excel and then processes it. Our client drops off the files and we process them (important because I don't have any control over the original file).

我用使用OLEDB库,填补了一个数据集(我讨厌写作的code,说真的,有没有code,一个.NET开发人员畏惧写多一点呢?)。该文件包含像30829300,30071500,等等......对于这些列中的数据类型是一些数字文本。

I use the OleDb library to fill up a dataset (I hate writing that code. Seriously, is there any code that a .Net developer dreads writing more than that?). The file contains some numbers like 30829300, 30071500, etc... The data type for those columns is "Text."

这些数字转换为科学记数法,当我输入的数据。反正是有prevent这种情况的发生?

Those numbers are converted to scientific notation when I import the data. Is there anyway to prevent this from happening?

克里斯

推荐答案

使用OLEDB库,更多的,往往不是搞乱在Excel US preadsheet您的数据。这主要是因为它迫使一切到固定式柱布局,中的前8个细胞每列中猜测的在距值的每个列的类型。如果猜测错误,你最终转化为科学,符号数字串。布莱什!

The OleDb library will, more often than not, mess up your data in an Excel spreadsheet. This is largely because it forces everything into a fixed-type column layout, guessing at the type of each column from the values in the first 8 cells in each column. If it guesses wrong, you end up with digit strings converted to scientific-notation. Blech!

要避免这种情况你最好跳过使用OLEDB和直接读取表自己。您可以使用Excel的COM接口(也布莱赫!),或第三方的.NET Excel兼容的读卡器做到这一点。 US preadsheetGear 就是这样的一个库,效果相当好,并具有一个接口,非常类似于Excel的COM接口。

To avoid this you're better off skipping the OleDb and reading the sheet directly yourself. You can do this using the COM interface of Excel (also blech!), or a third-party .NET Excel-compatible reader. SpreadsheetGear is one such library that works reasonably well, and has an interface that's very similar to Excel's COM interface.

这篇关于从Excel中的净进口时科学记数法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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