0
我有一個將DataGridView導出爲CSV的方法。但我有一個場景,我有一個DataSet像2-3表init。我想將它導出到一個單獨的CSV文件中,每個DataSet表在一個單獨的CSV表單中。如何將多個DataSet表導出到多個CSV表單?
這裏是我的方法,其中一個DataGridView轉換成CSV文件(注意我也會接受的C#代碼,如果它可以使用在線工具轉換爲Vb)中:
Private Sub subExportDGVToCSV(ByVal strExportFileName As String, ByVal DataGridView As DataGridView, Optional ByVal blnWriteColumnHeaderNames As Boolean = False, Optional ByVal strDelimiterType As String = ",")
Dim sr As StreamWriter = File.CreateText(strExportFileName)
Dim strDelimiter As String = strDelimiterType
Dim intColumnCount As Integer = DataGridView.Columns.Count - 1
Dim strRowData As String = ""
If blnWriteColumnHeaderNames Then
For intX As Integer = 0 To intColumnCount
strRowData += Replace(DataGridView.Columns(intX).Name, strDelimiter, "") & IIf(intX < intColumnCount, strDelimiter, "")
Next intX
sr.WriteLine(strRowData)
End If
For intX As Integer = 0 To DataGridView.Rows.Count - 1
strRowData = ""
For intRowData As Integer = 0 To intColumnCount
strRowData += Replace(DataGridView.Rows(intX).Cells(intRowData).Value, strDelimiter, "") & IIf(intRowData < intColumnCount, strDelimiter, "") '''''''''highlights this row
Next intRowData
sr.WriteLine(strRowData)
Next intX
sr.Close()
End Sub