早上好,将数据从datagrid导出到csv文件时遇到麻烦。
Sub csv()
Dim headers = (From header As DataGridViewColumn In dgShow.Columns.Cast(Of DataGridViewColumn)()
Select header.HeaderText).ToArray
Dim rows = From row As DataGridViewRow In dgShow.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
这是我的示例代码
这里是数据网格
内部csv文件
答案 0 :(得分:0)
这是我的解决方法:
sw.WriteLine(String.Join(",", r).Replace(vbCrLf, [String].Empty))