-2
Function ExportListview2CSV(ByVal lstview As ListView) As Boolean
Dim saveFileDialog1 As New SaveFileDialog()
Dim csvFileContents As New System.Text.StringBuilder
Dim CurrLine As String = String.Empty
saveFileDialog1.Filter = "CSV|*.csv"
saveFileDialog1.Title = "Save an CSV File"
csvFileContents.AppendLine("Service Provider Name: |" & cbodestproname.Text)
'csvFileContents.AppendLine(cbodestproname.Text)
csvFileContents.AppendLine("Circel Name: |" & cbodestcirclename.Text)
'csvFileContents.AppendLine(cbodestcirclename.Text)
csvFileContents.AppendLine("Month: |" & dtpDate.Text)
' csvFileContents.AppendLine(dtpDate.Text)
csvFileContents.AppendLine("Type of File: |" & cbotypeoffile.Text)
' csvFileContents.AppendLine(cbotypeoffile.Text)
csvFileContents.AppendLine("")
'Write out the column names as headers for the csv file.
For columnIndex As Int32 = 1 To lstview.Columns.Count - 2
CurrLine &= (String.Format("{0}|", lstview.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 lstview.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.
If saveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
If saveFileDialog1.FileName <> "" Then
Dim Sys As New System.IO.StreamWriter(saveFileDialog1.FileName)
Sys.WriteLine(csvFileContents.ToString)
Sys.Flush()
Sys.Dispose()
MsgBox("Data's are Saved Succesfully to " & saveFileDialog1.FileName, MsgBoxStyle.Information)
End If
End If
End Function
我想排除從第一記錄和最後一行 我應該在哪裏做在上面的代碼中chages
plz幫助我
thanx提前。
您應該將示例代碼調整到最小。此外,這個問題與導出爲CSV格式幾乎沒有關係,因此標題有誤導性 – blubb 2011-06-06 13:09:57