Экспорт в текст в xojo
Я хочу экспортировать данные из списка,
Listbox1.AddRow "001", "Orange", "1.00","Arief" Listbox1.AddRow "001", "Apple", "1.00","Arief" Listbox1.AddRow "001", "Banana", "1.00","Arief" Listbox1.AddRow "004", "Orange", "1.00","Arief" Listbox1.AddRow "005", "Apple", "1.00","Brandon" Listbox1.AddRow "006", "Banana", "1.00","Brenda" dim f as folderitem dim tisx as TextOutputStream f = new folderitem("item.txt") tisx = f.CreateTextFile dim Last_first_word as String dim maxRow as Integer = Listbox1.listcount-1 for row as integer = 0 to maxRow if Listbox1.Cell(row,0)<> Last_first_word then tisx.WriteLine "" tisx.writeline listBox1.cell(row,0) tisx.WriteLine listBox1.cell(row,1)+" "+listBox1.cell(row,2) Last_first_word=Listbox1.Cell(row,0) else tisx.WriteLine listBox1.cell(row,1)+" "+listBox1.cell(row,2) end if next tisx.Close
Я хочу классифицировать все элементы, которые имеют одинаковый код, и поставить имя в конце. Как сделать результат как,
001 Orange 1.00 Apple 1.00 Banana 1.00 Arief 004 Orange 1.00 Arief 005 Apple 1.00 Brandon 006 Banana 1.00 Brenda
Спасибо
С Уважением,
Arief
1 ответ
Вам также нужно сохранить имя, чтобы вы могли отобразить его, прежде чем переходить к новой группе данных. Требовалась лишь небольшая настройка вашего кода:
Listbox1.DeleteAllRows
ListBox1.AddRow("001", "Orange", "1.00", "Arief")
ListBox1.AddRow("001", "Apple", "1.00", "Arief")
ListBox1.AddRow("001", "Banana", "1.00", "Arief")
ListBox1.AddRow("004", "Orange", "1.00", "Arief")
ListBox1.AddRow("005", "Apple", "1.00", "Brandon")
ListBox1.AddRow("006", "Banana", "1.00", "Brenda")
Dim f As FolderItem
Dim tisx As TextOutputStream
f = SpecialFolder.Desktop.Child("item.txt")
tisx = f.CreateTextFile
Dim Last_first_word As String
Dim lastName As String
Dim maxRow As Integer = Listbox1.ListCount - 1
For row As Integer = 0 To maxRow
If Listbox1.Cell(row, 0) <> Last_first_word Then
If lastName <> "" Then tisx.WriteLine(lastName)
tisx.WriteLine("")
tisx.WriteLine(ListBox1.Cell(row, 0))
tisx.WriteLine(ListBox1.Cell(row, 1) + " " + ListBox1.Cell(row, 2))
Last_first_word = ListBox1.Cell(row, 0)
lastName = ListBox1.Cell(row, 3)
Else
tisx.WriteLine(ListBox1.Cell(row, 1) + " " + ListBox1.Cell(row, 2))
End If
Next
If lastName <> "" Then tisx.WriteLine(lastName)
tisx.Close
Чтобы это работало, данные должны быть отсортированы по номеру группы.