在我的表单中,我有一个ListView,我想将其数据导出到Excel文件。这是我的代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim csvFileContents As New System.Text.StringBuilder
Dim CurrLine As String = String.Empty
'Write out the column names as headers for the csv file.
For columnIndex As Int32 = 0 To ListView1.Columns.Count - 1
CurrLine &= (String.Format("{0};", ListView1.Columns(columnIndex).Text))
Next
'Remove trailing comma
csvFileContents.AppendLine(CurrLine.Substring(0, CurrLine.Length - 1))
CurrLine = String.Empty 'Write out the data.
For Each item As ListViewItem In ListView1.Items
For Each subItem As ListViewItem.ListViewSubItem In item.SubItems
CurrLine &= (String.Format("{0};", subItem.Text))
Next
'Remove trailing comma
csvFileContents.AppendLine(CurrLine.Substring(0, CurrLine.Length - 1))
CurrLine = String.Empty
Next
'Create the file.
Dim Sys As New System.IO.StreamWriter("D:\Test.csv")
Sys.WriteLine(csvFileContents.ToString)
Sys.Flush()
Sys.Dispose()
End Sub
代码工作正常,但是当我打开文件时,阿拉伯数据没有被正确复制,这就是它的样子:
نبيل;سي عÙ
如何解决此问题?谢谢