将数字导出为VB.Net中的DataGridView中的文本为CSV

时间:2017-07-24 20:49:02

标签: vb.net csv datagridview export-to-csv

我从DataGridView to CSV File获得了这个教程,我遇到了一个由数字组成的字段的问题,特别是那些以0开头的字段。

   Dim headers = (From header As DataGridViewColumn In PadGridView.Columns.Cast(Of DataGridViewColumn)()
                   Select header.HeaderText).ToArray
    Dim rows = From row As DataGridViewRow In PadGridView.Rows.Cast(Of DataGridViewRow)()
               Where Not row.IsNewRow
               Select Array.ConvertAll(row.Cells.Cast(Of DataGridViewCell).ToArray, Function(c) If(c.Value IsNot Nothing, c.Value.ToString, ""))
    Using sw As New IO.StreamWriter("export.csv")
        sw.WriteLine(String.Join(",", headers))
        For Each r In rows
            sw.WriteLine(String.Join(",", r))
        Next
    End Using
    Process.Start("export.csv")
End Sub

当前输出:

  • 2.97E + 104
  • 18523696,应该是018523696

是否有可能将所有字段导出为文本,因此数字集不会缩短或格式不同?

提前谢谢/

0 个答案:

没有答案