我有一个小函数,可以从存储在数据网格中的字符串创建一个 .csv 文件。
Dim rowcount As Integer = DataGridView1.Rows.Count - 1
For m As Integer = 0 To rowcount
Dim strrowvalue As String = ""
strrowvalue += CStr(DataGridView1.Rows(m).Cells(0).Value)
For n As Integer = 1 To DataGridView1.Columns.Count - 1
If DataGridView1.CurrentCell.Value Is DBNull.Value Then
strrowvalue += "," + "0"
End If
If DataGridView1.Rows(m).Cells(n).Value Is DBNull.Value Then
strrowvalue += "," + "0"
Else
strrowvalue += "," + CStr(DataGridView1.Rows(m).Cells(n).Value)
End If
Next
If m <> rowcount Then
streamwriter.WriteLine(strrowvalue)
End If
Next
然而,在第一个值之后插入一个换行符。这会导致 Excel 和其他程序将第一个值放在第 1 行,然后将该行的其余值放在第 2 行。
例子:
100 ,
555,333,333,666,777
200 ,
444,555,453,345,778
它应该是:
100,555,333,333,666,777
200,444,555,453,345,778
有任何想法吗?
编辑:问题已被修改以表明它是插入字符串的换行符,而不是空格。