|
Tutorials
|
|
Function below Exports a Listview to a Comma Separated Value file.
Show/Hidden vbnet code Function ExportListview2Excel(ByVal lstview As ListView) As Boolean
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 lstview.Columns.Count - 1
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.
Dim Sys As New System.IO.StreamWriter("C:\Test.csv")
Sys.WriteLine(csvFileContents.ToString)
Sys.Flush()
Sys.Dispose()
End Function
|
Comments
I think it's best to copy the code in the statement that you need and not a function.
'example:
Private Sub Button1_Click () Handles Button.Click
'The code here ...
End Sub
RSS feed for comments to this post