GizStack
View .mdOpen in ChatGPTOpen in Claude

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.

gizlang
import * as Xlsx from "gizlang:xlsx";

Types

Cell

gizlang
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.

  • blank
  • number
  • text
  • boolean
  • date
  • time

Sheet

gizlang
type Sheet

One 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

gizlang
function sheet(name: string, head: Vec<string>): Sheet

A 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

gizlang
function column(at: i64): string

The letters of the column AT (0: A, 26: AA).

Effects: fail.

serial

gizlang
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

gizlang
function workbook(sheets: Vec<Sheet>): bytes

SHEETS as one XLSX file.

Effects: fail.

rows

gizlang
function rows(data: bytes, most: i64): Vec<Vec<string>> throws string

The 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

gizlang
function Sheet.row(self: mut Sheet, cells: Vec<Cell>): void

Adds a row of CELLS.

Effects: fail.

Sheet.protect

gizlang
function Sheet.protect(self: mut Sheet): void

Makes 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

gizlang
function Sheet.count(self: Sheet): i64

How many rows the sheet holds, its head included.