Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Util/Read CSV File
This example is the version from Thu, 10th Jan 2018.
Project "Read CSV File.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub NewDocument()
dim f as FolderItem = GetOpenFolderItem("")
if f<>Nil then
OpenDocument f
end if
End EventHandler
EventHandler Sub OpenDocument(item As FolderItem)
ReadCSV item
End EventHandler
Sub ReadCSV(file as FolderItem)
dim t as TextInputStream = TextInputStream.Open(file)
t.Encoding = Encodings.UTF8 // we expect here: UTF-8
// prepare window
dim w as new TextWindow
dim list as listbox = w.List
w.Title = file.DisplayName
// read header
dim header as string = t.ReadLine
dim headerItems() as string = SplitCommaSeparatedValuesMBS(header)
dim u as integer = UBound(headerItems)
list.ColumnCount = u+1
for i as integer = 0 to u
list.Heading(i) = headerItems(i)
next
// read rows
dim lines() as string
while not t.EOF
dim line as string = t.ReadLine
if line.trim.len>0 then // ignore empty lines
lines.append line
end if
wend
dim AllLines as string = Join(lines, EndOfLine)
dim items() as string = SplitCommaSeparatedValuesMBS(AllLines, "")
dim n as integer
while n < items.Ubound
list.AddRow ""
for i as integer = 0 to u
list.cell(list.LastIndex, i) = items(n)
list.CellHelpTag(list.LastIndex, i) = items(n)
n = n + 1
next
wend
End Sub
End Class
Class TextWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project
See also:
The items on this page are in the following plugins: MBS Util Plugin.