ReferenceAPI
Workbook
Create, open, render, check and save a workbook.
Create, open, render, check and save a workbook. The same text agents read through help().
spreadsheets
Section titled “spreadsheets”Build a workbook with workbook.sheets.add(name), write cells through sheet.range("A1:C3") (values, formulas, format), then look with sheet.render(), check with workbook.lint() and publish with workbook.finalize(). Formulas compute as you write them; arrays spill. Help topics: workbook, sheet, range, CellFormatInput, SheetTableOptions, ConditionalRuleInput, ValidationInput, SheetChartOptions, functions, numberFormats.
const s = workbook.sheets.add("Model"); s.range("A1").values = [["Month", "Revenue"], ["Jan", 120], ["Feb", 150]]; s.range("B4").formula = "=SUM(B2:B3)";Workbook.create
Section titled “Workbook.create”Workbook.create(options: { theme?: ThemePresetName | ThemePreset | string }?): WorkbookA new, empty workbook; add sheets with wb.sheets.add("Name"). theme applies a preset (Workbook.create({ theme: "ledger" })): its colors and fonts for tables, charts and rules.
wb.sheets.add("Name")Workbook.create({ theme: "ledger" })Workbook.fromJSON
Section titled “Workbook.fromJSON”Workbook.fromJSON(json: WorkbookJSON): WorkbookA workbook from toJSON().
Workbook.open
Section titled “Workbook.open”Workbook.open(file: string | Uint8Array): Promise<Workbook>Opens an .xlsx (or an .xltx template) to edit it: const wb = await Workbook.open("plan.xlsx"). Cells, formats, tables, rules and charts are read; what you change is saved into the file and everything else (pivot tables, macros-free extras, styles you don’t touch) stays as it was.
const wb = await Workbook.open("plan.xlsx")workbook
Section titled “workbook”An Excel workbook: const wb = Workbook.create(); const s = wb.sheets.add("Model"); then s.range("A1").values = [["Month", "Revenue"], ["Jan", 120]] and await wb.save("model.xlsx").
| Option | Type | Description |
|---|---|---|
creationId (required) |
string |
A unique id for this workbook. |
theme (required) |
Theme |
Theme colors and fonts (the same as a deck’s): wb.theme.set({ colors: { accent1: "#2346C8" } }). |
now (required) |
Date | undefined |
The clock for TODAY() and NOW(); default the real time. |
Workbook.create() (required) |
method |
A new, empty workbook; add sheets with wb.sheets.add("Name"). |
Workbook.open() (required) |
method |
Opens an .xlsx (or an .xltx template) to edit it: const wb = await Workbook.open("plan.xlsx"). |
sheets.… (required) |
collection |
|
names.… (required) |
collection |
|
recalculate() (required) |
method |
Computes every formula now (reads and saves do this on their own when something changed). |
circularReferences (required) |
readonly CircularReference[] |
Formula cells in a cycle, from the last calculation. |
lint() (required) |
method |
Checks for formula errors, cycles, #### columns, clipped text, numbers stored as text, typed-in numbers in formulas, unformatted numbers and empty charts. |
inspect() (required) |
method |
Compact records of the workbook: sheets, cell values row by row, formulas with results, tables, charts and names. |
toJSON() (required) |
method |
The whole workbook as JSON (cells, formats, tables, rules, charts, names, theme and images), for saving between turns: Workbook.fromJSON(wb.toJSON()) gives an equal workbook. |
Workbook.fromJSON() (required) |
method |
A workbook from toJSON(). |
finalize() (required) |
method |
Publishes the workbook: exports and validates it, checks your requirements (sheets, tables, charts, expected values in key cells) and lint, then writes a new .xlsx (never overwriting). |
trace() (required) |
method |
Where a number comes from: the cell’s formula and value, and the cells, ranges and names it reads, followed depth levels down (default 3): wb.trace("Summary!B2"). |
toProto() (required) |
method |
The document model as a protobuf message. |
toBytes() (required) |
method |
Encodes the workbook as .xlsx bytes using the Artiwright engine. |
save() (required) |
method |
Writes the workbook to an .xlsx file. |
workbook.circularReferences
Section titled “workbook.circularReferences”circularReferences: workbook.circularReferences: readonly CircularReference[]Formula cells in a cycle, from the last calculation.
workbook.creationId
Section titled “workbook.creationId”creationId: workbook.creationId: stringA unique id for this workbook.
workbook.finalize
Section titled “workbook.finalize”workbook.finalize(options: WorkbookFinalizeOptions): Promise<WorkbookFinalizeResult>Publishes the workbook: exports and validates it, checks your requirements (sheets, tables, charts, expected values in key cells) and lint, then writes a new .xlsx (never overwriting). await wb.finalize({ output: "model.xlsx", requirements: { values: [{ cell: "Checks!B2", equals: 0 }] } }).
Options: WorkbookFinalizeOptions.
await wb.finalize({ output: "model.xlsx", requirements: { values: [{ cell: "Checks!B2", equals: 0 }] } })workbook.inspect
Section titled “workbook.inspect”workbook.inspect(options: WorkbookInspectOptions?): WorkbookInspectResultCompact records of the workbook: sheets, cell values row by row, formulas with results, tables, charts and names. wb.inspect({ sheet: "Model", kind: "formula" }).ndjson.
Options: WorkbookInspectOptions.
wb.inspect({ sheet: "Model", kind: "formula" }).ndjsonworkbook.lint
Section titled “workbook.lint”workbook.lint(options: WorkbookLintOptions?): WorkbookLintResultChecks for formula errors, cycles, #### columns, clipped text, numbers stored as text, typed-in numbers in formulas, unformatted numbers and empty charts. Each finding names the sheet and cell and suggests a fix. wb.lint({ rules: "formula/" }).
Options: WorkbookLintOptions.
wb.lint({ rules: "formula/" })workbook.names.add
Section titled “workbook.names.add”workbook.names.add(name: string, refersTo: string, options: { sheet?: string; comment?: string }?): WorkbookNamesNames a cell, range or value for formulas: wb.names.add("Growth", "Inputs!$B$2"), then =B2*(1+Growth). { sheet } scopes the name to one sheet.
wb.names.add("Growth", "Inputs!$B$2")=B2*(1+Growth)workbook.names.get
Section titled “workbook.names.get”workbook.names.get(name: string): DefinedNameInput | undefinedA defined name by name (not case-sensitive).
workbook.names.items
Section titled “workbook.names.items”workbook.names.items: readonly DefinedNameInput[]Every defined name.
workbook.names.remove
Section titled “workbook.names.remove”workbook.names.remove(name: string): voidDeletes a defined name.
workbook.now
Section titled “workbook.now”now: workbook.now: Date | undefinedThe clock for TODAY() and NOW(); default the real time.
workbook.recalculate
Section titled “workbook.recalculate”workbook.recalculate(): CircularReference[]Computes every formula now (reads and saves do this on their own when something changed). Returns formula cells that refer to themselves; those show 0, as in Excel.
workbook.save
Section titled “workbook.save”workbook.save(path: string): Promise<void>Writes the workbook to an .xlsx file.
workbook.sheets.active
Section titled “workbook.sheets.active”workbook.sheets.active: Worksheet | undefinedThe sheet shown when the file opens (default the first).
workbook.sheets.add
Section titled “workbook.sheets.add”workbook.sheets.add(name?: string, index?: number): WorksheetAdds a sheet at the end (or at index): wb.sheets.add("Model").
wb.sheets.add("Model")workbook.sheets.get
Section titled “workbook.sheets.get”workbook.sheets.get(nameOrIndex: string | number): Worksheet | undefinedA sheet by name (not case-sensitive) or 0-based position.
workbook.sheets.items
Section titled “workbook.sheets.items”workbook.sheets.items: readonly Worksheet[]The sheets in tab order.
workbook.sheets.length
Section titled “workbook.sheets.length”workbook.sheets.length: numberHow many sheets the workbook has.
workbook.sheets.move
Section titled “workbook.sheets.move”workbook.sheets.move(sheet: Worksheet | string, to: number): voidMoves a sheet to a position, 0 being first.
workbook.sheets.remove
Section titled “workbook.sheets.remove”workbook.sheets.remove(sheet: Worksheet | string): voidDeletes a sheet.
workbook.theme
Section titled “workbook.theme”theme: workbook.theme: ThemeTheme colors and fonts (the same as a deck’s): wb.theme.set({ colors: { accent1: "#2346C8" } }).
workbook.toBytes
Section titled “workbook.toBytes”workbook.toBytes(): Promise<Uint8Array>Encodes the workbook as .xlsx bytes using the Artiwright engine.
workbook.toJSON
Section titled “workbook.toJSON”workbook.toJSON(): WorkbookJSONThe whole workbook as JSON (cells, formats, tables, rules, charts, names, theme and images), for saving between turns: Workbook.fromJSON(wb.toJSON()) gives an equal workbook.
Workbook.fromJSON(wb.toJSON())workbook.toProto
Section titled “workbook.toProto”workbook.toProto(): pb.DocumentThe document model as a protobuf message.
workbook.trace
Section titled “workbook.trace”workbook.trace(cell: string, options: { depth?: number }?): TraceNodeWhere a number comes from: the cell’s formula and value, and the cells, ranges and names it reads, followed depth levels down (default 3): wb.trace("Summary!B2").
levels down (default 3):