我想要做的是将我的 CSV 文件输入到数据表中,然后循环遍历并将其重新保存为 csv,去掉所有值周围的引号,这样我就可以将值与另一个 csv 连接起来。
第一次导出时,它工作正常。如果我碰巧再次运行它,它会添加一个名为“No Name”的新列。如果我再次运行它,它将添加另一个“无名称”选项卡,依此类推。到目前为止,这是我的代码。
Dim currentrow As New System.Text.StringBuilder
Dim entirefile As New System.Text.StringBuilder
Dim i As Integer = 0
For Each column As DataColumn In dt1.Columns
currentrow.Append("" & column.ColumnName & ",")
Next
entirefile.AppendLine(currentrow.ToString)
For Each row As DataRow In dt1.Rows
currentrow = New System.Text.StringBuilder
i = 0
For Each column As DataColumn In dt1.Columns
currentrow.Append("" & row.Item(i) & ",")
i += 1
Next
entirefile.AppendLine(currentrow.ToString)
Next
Dim sw As New System.IO.StreamWriter("C:\CSV\MlnExp.csv")
sw.Write(entirefile)
sw.Dispose()