我从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
当前输出:
是否有可能将所有字段导出为文本,因此数字集不会缩短或格式不同?
提前谢谢/