gizlang:xlsx
XLSX (Office Open XML SpreadsheetML) workbooks, written: sheets of typed cells with a bold, frozen and filtered head row. Text goes inline in each cell (no shared string table), so a sheet is written row by row in one pass. A number keeps its decimal text as given; a date or time becomes Excel's serial day number with a date format, so a spreadsheet sorts and computes with it. Each part is deflated in one zip archive (gizlang:compress). A protected sheet is read-only in a spreadsheet, its filter and sort still free. rows reads the first sheet of a workbook back as texts.
import * as Xlsx from "gizlang:xlsx";Types
Cell
type Cell = | { kind: "blank"; } | { kind: "number"; v: string; } | { kind: "text"; v: string; } | { kind: "boolean"; v: bool; } | { kind: "date"; v: string; } | { kind: "time"; v: string; }One cell: nothing, a number (its decimal text), text, a boolean, a date (YYYY-MM-DD) or a time (YYYY-MM-DD HH:MM:SS,
with optional fraction; a T may stand for the space). A date or time that does not parse is written as text.
blanknumbertextbooleandatetime
Sheet
type SheetOne sheet being written: its name, the XML of its rows so far, its row count, each column's widest text and whether it is protected.
name:string
Functions
sheet
function sheet(name: string, head: Vec<string>): SheetA sheet NAME whose first row is HEAD, bold, frozen and filtered. Excel allows 31 characters and no []:*?/\ in a name: others are
replaced.
Effects: fail.
column
function column(at: i64): stringThe letters of the column AT (0: A, 26: AA).
Effects: fail.
serial
function serial(v: string): Option<f64>Excel's serial day of a date or time text: days since 1899-12-30, the time of day as a fraction.
Effects: fail.
workbook
function workbook(sheets: Vec<Sheet>): bytesSHEETS as one XLSX file.
Effects: fail.
rows
function rows(data: bytes, most: i64): Vec<Vec<string>> throws stringThe rows of the first sheet of the XLSX file DATA, at most MOST of them: each row's cell texts by column, a missing
cell "". A number reads as its decimal text; a cell whose number format shows a date reads as YYYY-MM-DD, or
YYYY-MM-DD HH:MM:SS with a time of day; a boolean as true or false; an error as its code (#N/A). A formula
reads as the value the spreadsheet saved with it.
Effects: fail, read, write, console, io.
Methods
Sheet.row
function Sheet.row(self: mut Sheet, cells: Vec<Cell>): voidAdds a row of CELLS.
Effects: fail.
Sheet.protect
function Sheet.protect(self: mut Sheet): voidMakes the sheet read-only in a spreadsheet: its cells cannot change, while filtering and sorting still work. It holds no password: protection guards against a slip, never against a person who wants to edit.
Sheet.count
function Sheet.count(self: Sheet): i64How many rows the sheet holds, its head included.