我在asp.net中有一个包含5列的gridview,并且只想用csv格式的分号(DBS30606XRIR;1,748.09
)导出两列。我可以导出它。但我的问题是,当gridview中的price列包含逗号时,它将在导出后转到文件中的另一个单元格。我只希望它在一个单元格中。以下是我的代码。
If GVuplaodPriceList.Rows.Count <> 0 Then
Dim sw As TextWriter = New StreamWriter("U:\ListPrice.csv")
For i As Integer = 0 To GVuplaodPriceList.Rows.Count - 1
sw.Write(GVuplaodPriceList.Rows(i).Cells(4).Text.ToString() + ";")
sw.Write(GVuplaodPriceList.Rows(i).Cells(5).Text.ToString())
sw.WriteLine()
Next
sw.WriteLine("")
sw.Close()
MsgBox("Data Exported Successfully", MsgBoxStyle.Information, "Data Exported")
答案 0 :(得分:0)
选项1 - 用引号括起来:
sw.Write(String.Concat("""",GVuplaodPriceList.Rows(i).Cells(5).Text.ToString(),"""",";"))
选项2 - 删除有问题的逗号
sw.Write(String.Concat(GVuplaodPriceList.Rows(i).Cells(5).Text.ToString.Replace("""", ""),";"))