[ad_1]
私はプログラミングの初心者なので、リスト ビューにリストされている値を CSV ファイルに書き込む方法を知りたいです。
ありがとう
解決策 1
以下のアルゴリズムとそれに応じたコードを使用してください
VB
Variable : StrCSVFiles StrCSVFiles = "" Loop through all list item (increment x as index) StrCSVFiles = StrCSVFiles + Listview1[x].listitem(0) + "," + Listview1[x].listitem(1) x = x +1 End Loop Create file File.Write (StrCSVFiles)
解決策 2
Public Sub ExportListviewToCsv(ByRef theListView As ListView, csvExportFileName As String, Optional writeHeader As Boolean = True, Optional useQuotes As Boolean = True) Dim fileNum As Integer Dim theListItem As ListItem Dim idx As Long fileNum = FreeFile(255) Open csvExportFileName For Output As #fileNum If writeHeader = True Then For idx = 1 To theListView.ColumnHeaders.Count If useQuotes = True Then Print #fileNum, Chr(34) & theListView.ColumnHeaders(idx).Text & Chr(34); Else Print #fileNum, theListView.ColumnHeaders(idx).Text; End If If idx < theListView.ColumnHeaders.Count Then Print #fileNum, ","; End If Next Print #fileNum, "" End If For Each theListItem In theListView.ListItems If useQuotes = True Then Print #fileNum, Chr(34) & theListItem.Text & Chr(34); Else Print #fileNum, theListItem.Text; End If If theListItem.ListSubItems.Count > 0 Then Print #fileNum, ","; For idx = 1 To theListItem.ListSubItems.Count If useQuotes = True Then Print #fileNum, Chr(34) & theListItem.SubItems(idx) & Chr(34); Else Print #fileNum, theListItem.SubItems(idx); End If If idx < theListItem.ListSubItems.Count Then Print #fileNum, ","; End If Next End If Print #fileNum, "" Next Close #fileNum End Sub
[ad_2]
コメント