我有一个功能可以成功地将数据从CSV加载到datagridview。问题是在某些列中有很长的数字,它们看起来像5.00E + 14。理想情况下,我想在CSV文件中更改该值,因为我打算将CSV导出到另一个数据库。有什么想法吗?
Dim Lines As String() = File.ReadAllLines(sFile)
Dim Fields As String()
Fields = Lines(0).Split(New Char() {","c})
Dim Cols As Integer = Fields.GetLength(0)
Dim dt As New DataTable()
'1st row must be column names; force lower case to ensure matching later on.
For i As Integer = 0 To Cols - 1
dt.Columns.Add(Fields(i).ToLower(), GetType(String)).AllowDBNull = True
Next
Dim Row As DataRow
' = 1 to skip the first line
For i As Integer = 1 To Lines.GetLength(0) - 1
Fields = Lines(i).Split(New Char() {","c})
Row = dt.NewRow()
For f As Integer = 0 To Cols - 1
Row(f) = Fields(f)
Next
dt.Rows.Add(Row)
Next
DataGridView2.DataSource = dt
答案 0 :(得分:0)
您需要手动或使用
更改目标单元格中的格式Range("F7:G32").NumberFormat = "0.00"
使用您想要使用的范围和数字格式。您无法在csv文件中更改它,因为无论数字如何,使用excel中的默认常规格式,它将以科学格式显示长数字。