如何处理单元格值“2.72E + 11” [英] How to handle cell value "2.72E+11"

查看:98
本文介绍了如何处理单元格值“2.72E + 11”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在读一个.csv文件。其中一个单元格包含值

Hi All,

I am reading a .csv file. One of the cell contains a value "

2.72E+11





当我douuble点击单元格时,值为271500000000 ..我需要将此值存储在我的数据集中,我该如何实现?请帮助。



谢谢。


"
When i douuble click the cell the value is 271500000000..I need to store this value in my Dataset how can i achieve this?Please help.

Thanks.

推荐答案

我建​​议您使用OleDb驱动程序来读取逗号分隔文件。



步骤:

1)创建新的Windows应用程序项目

2)添加控件:

- TextBox(名称:TxtFileToLoad) - 在这里你将定义csv文件的路径

- DataGridView(名称:DataGridView1) - 显示数据

- 按钮(名称:BtnLoadData)

3)复制并粘贴下面的代码:

I suggest you to use OleDb drivers to read comma separated files.

Steps to do:
1) create new windows application project
2) add controls:
- TextBox (Name: TxtFileToLoad) - here you''ll define path to csv file
- DataGridView (Name: DataGridView1) - to display data
- Button (Name: BtnLoadData)
3) copy and paste below code:
Private Sub BtnLoadData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLoadData.Click
    Dim scon As String = String.Empty, scom As String = String.Empty
    Dim con As OleDb.OleDbConnection = Nothing, com As OleDb.OleDbCommand = Nothing, rdr As OleDb.OleDbDataReader = Nothing
    Dim sFileName As String = String.Empty
    Dim dt As Data.DataTable = Nothing, r As DataRow = Nothing
    Try

        sFileName = Me.TxtFileToLoad.Text
        scon = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & IO.Path.GetDirectoryName(sFileName) & ";Extended Properties='Text;HDR=Yes;Schema=schema.ini;';"
        scom = CreateCommand(sFileName)
        con = New OleDb.OleDbConnection(scon)
        con.Open()
        com = New OleDb.OleDbCommand(scom, con)
        rdr = com.ExecuteReader()
        dt = New Data.DataTable
        dt.Load(rdr)
        Me.DataGridView1.DataSource = dt

    Catch ex As OleDb.OleDbException
        MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")

    Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...")
    Finally
        If Not rdr Is Nothing Then rdr.Close()
        If Not com Is Nothing Then com.Dispose()
        If Not com Is Nothing Then con.Close() : con.Dispose()
    End Try
End Sub

Function CreateCommand(ByVal sFileName As String) As String
    Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()

    sb.AppendLine("SELECT *")
    sb.AppendLine("FROM " & sFileName & ";")

    Return sb.ToString

End Function



4)定义 schema.ini 文件;将它存储在放置数据文件的同一文件夹中。

有关schema.ini文件的更多信息(文本文件驱动程序): http://msdn.microsoft.com/en-us/library/windows/desktop/ms709353%28v=vs.85%29 .aspx [ ^ ]

5)运行项目



我的示例数据(someData2.csv):


4) define schema.ini file; store it in the same folder where the data file is placed.
More about schema.ini file (Text File Driver): http://msdn.microsoft.com/en-us/library/windows/desktop/ms709353%28v=vs.85%29.aspx[^]
5) Run project

My example data (someData2.csv):

some data 1,271500000000,another data 1, 500
some data 2,381700000000,another data 2, 900
some data 3,211500000000,another data 3, 1500
some data 4,932500000000,another data 4, 300





我的示例模式:



My example schema:

[someData2.csv]
Format=Delimited(,)
ColNameHeader=FALSE
DecimalSymbol=.
NumberDigits=0
MaxScanRows=0
StartScanRow=0
Col1=Column1 Text Width 30
Col2=Column2 Double
Col3=Column3 Text Width 30
Col4=Column4 Long





DataGridView显示 271500000000 271500000000 不是 2.72E + 11


这篇关于如何处理单元格值“2.72E + 11”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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