Slide 25 of 37
Spreadsheets
proc main(): void {
sheets := using "./ledger.xlsx" as xlsx
if sheets is Result.Ok(tables) {
if tables bounds 0 {
echo len(tables[0])
}
} else if sheets is Result.Error(err) {
echo "no workbook yet: {err.message}"
}
}
using reads more than a CSV. as xlsx and as ods each read a whole workbook and answer with a Result<Table[dyn], hive.TableError> — one Table per sheet, in document order, so an empty sheet is an empty Table rather than a missing one. Both readers are dependency-free. An xlsx cell arrives as the file stores it, with one exception: a date is kept internally as a day count, so the cell's own number format is consulted to catch exactly those and render them as a real date. An ods stores real dates already, so nothing there needs undoing.