Skip to content

Workbook

Individual workbook within a model. Contains Sheets which contain Cells. Contains its own dependency graph, for now at least, so no dependencies between workbooks.

  • emitter
charts: ChartCSF[];

cloud_connection: CloudConnection | null;

readonly comments: CommentsManager;

Workbook-level comment operations. See CommentsManager.


defect: string | null;

externals: External[];

id: string;

isExternal: boolean;

Whether this workbook was loaded as an external reference from another workbook.


metadata: GridMetadata;

mode: WorkbookMode;

EvaluationContext.mode


name: string;

readonly notes: NotesManager;

Workbook-level note operations. See NotesManager.


people: Person[] = [];

Authors of cell comments, or people mentioned in a cell comment.


ready: boolean = false;

replacedBy: string | null = null;

reserved for outside use (client loader)


readonly styles: StyleManager;

readonly tables: TableManager;

Table collection operations. See TableManager.


readonly theme: ThemeManager;

Get and set workbook theme properties.


type:
| "unknown"
| "airtable"
| "notion"
| "smartsheet"
| "csv"
| "excel"
| "form-submissions"
| "google-sheets"
| "native";

The origin of the workbook (Excel, Google Sheets, CSV, etc).


update_time: string | undefined;

version: number | undefined;

optional views: WorkbookView[];
get env(): Map<"isPrint" | "isMobile" | "username", MaybeBoxedFormulaArgument>;

Map<"isPrint" | "isMobile" | "username", MaybeBoxedFormulaArgument>

EvaluationContext.env


get errorLevel(): number;

number


get errors(): ModelError[];

ModelError[]


get lazyImportPromise(): Promise<void>;

Promise<void>

_applyWrite(
refStr,
value,
oldSheetCount,
oldSheetIndex): void;

Write value value to the given reference, or to the same address in the sheet with index oldSheetIndex if sheet count matches oldSheetCount

string

CellValue

number

number | null

void


_getExistingCachedFormulaCell(formula, prefix): object;

string

string = CACHED_FORMULA_CELL_ID_PREFIX

object

cell: DefinedName | null;
id: string;

_markCellsReferencingRemovedSheetForRecalculation()

Section titled “_markCellsReferencingRemovedSheetForRecalculation()”
_markCellsReferencingRemovedSheetForRecalculation(sheetBeingRemoved): void;

WorkSheet

void


_rewriteFormulasReferencingRenamedSheet(
sheet,
currentName,
newName): void;

Precondition: formula parser has finished importing (formulaParserReady has resolved).

WorkSheet

string

string

void


_writesIter(): IterableIterator<[string, CellValue, KnownVertexId]>;

Precondition: Workbook must be initialized

IterableIterator<[string, CellValue, KnownVertexId]>


addSheet(sheetName?, index?): WorkSheet;

Add a new empty sheet to the workbook

if no sheet name is provided a unique sheet name will be generated

string | null

number

if no index is provided the sheet will be appended to the list of sheets

WorkSheet


clearCachedFormulasExcept(formulas): void;

string[]

void


clearCells(ref): boolean;

Precondition: Workbook must be initialized

A reference to the cell, or range of cells, to clear. Defined names are not supported.

string | Reference

boolean

true if any changes were made (so a recalculation is in order).


deleteColumns(
sheetName,
columnIndex,
count): RewriteFormula;

Delete count columns at a specific index in the given sheet.

string

number

0-based column index

number

how many columns should be deleted

RewriteFormula


deleteRows(
sheetName,
rowIndex,
count): RewriteFormula;

Delete count rows at a specific index in the given sheet.

string

number

0-based row index

number

how many rows should be deleted

RewriteFormula


emit(event, ...arguments_): Emitter;

Emit an event, invoking all handlers registered for it.

string

The name of the event to emit.

any[]

Arguments to pass to the event handlers.

Emitter

The Emitter instance for method chaining.

EventEmitter.emit

getCell(cellId, sheetName?): Cell | null;

string

string | null

Cell | null


getGlobal(name):
| FormulaError
| DefinedName;

string

| FormulaError | DefinedName


getSheet(sheetName?): WorkSheet | null;

string | null

WorkSheet | null

the named sheet if sheetName is truthy (null if not found), else the first sheet.


getSheetByIndex(index?): WorkSheet | null;

Get a sheet of the given index or else, if index is not provided, the first sheet of this workbook.

the index of a sheet

number | null

WorkSheet | null

the sheet found at the given index, or else the first sheet if none was given. If no sheets are present this method returns null.


getSheetIndex(sheetName?): number | null;

Get the order index of a sheet with the given name.

string

the name of the sheet whose index should be returned. It will be matched case-insensitively.

number | null

The index of the sheet with the given name, or null if no sheet with that name exists, or 0 if no/empty name was given.


getSheets(): WorkSheet[];

WorkSheet[]


getSheetSize(sheetName?): [number, number];

Get the size of a sheet with the given name.

the name of the sheet whose size should be returned. It will be matched case-insensitively. If not provided, or empty, the size of the first sheet (0, 0) is returned.

string | null

[number, number]

The size of the sheet with the given name, or null if no sheet with that name exists, or (0, 0) if no/empty name was given.


getTable(name): Table | null;

string

Table | null


getTables(): Table[];

Table[]


getViews(): WorkbookView[];

Gets the workbook’s saved view configurations (active sheet, etc).

Copies are returned to prevent external mutation of the workbook’s views.

WorkbookView[]


hasListeners(event): boolean;

Check if there are any handlers registered for a specific event.

string

The name of the event.

boolean

true if there are one or more handlers, false otherwise.

EventEmitter.hasListeners
hasListeners(): boolean;

Check if there are any handlers registered for any event.

boolean

true if there are one or more handlers for any event, false otherwise.

EventEmitter.hasListeners

insertColumns(
sheetName,
columnIndex,
count,
toTheRight): RewriteFormula;

Insert count columns at a specific index in the given sheet.

string

number

0-based column index

number

how many columns to insert

boolean

determines whether the inserted columns are inserted to the left or right of the column at columnIndex.

RewriteFormula


insertRows(
sheetName,
rowIndex,
count,
below): RewriteFormula;

Insert count rows at a specific index in the given sheet.

string

number

0-based row index

number

how many rows to insert

boolean

determines whether the inserted rows are inserted below or above of the row at rowIndex.

RewriteFormula


isGlobal(name): boolean;

string

boolean


iterDataTableCells(): IterableIterator<Cell>;

IterableIterator<Cell>


iterFormulaCells(): IterableIterator<
| Cell
| DefinedName>;

IterableIterator< | Cell | DefinedName>


listenerCount(event): number;

Get the count of listeners for a specific event.

string

The name of the event.

number

The number of listeners for the event.

EventEmitter.listenerCount
listenerCount(): number;

Get the count of all event handlers in total.

number

The total number of event handlers.

EventEmitter.listenerCount

listeners(event): (...arguments_) => void[];

Retrieve the event handlers registered for a specific event.

string

The name of the event.

(…arguments_) => void[]

An array of functions registered as handlers for the event.

EventEmitter.listeners

mergeCells(
sheetName,
rangeStr,
options): void;

Merge a range of cells on the given sheet.

string

name of the sheet

string

range in A1 notation, e.g. “A1:B2”

boolean = true

if true (default), recalculate after merging; set to false to batch multiple merges before a single recalc

void

if the sheet does not exist, the range is a single cell, or overlaps an existing merge


moveCells(
from,
to,
recalcNow): RewriteFormula;

Precondition: formula parser has finished importing (formulaParserReady has resolved).

Must be the same dimensions as to

string | A1Reference

Must be the same dimensions as from

string | A1Reference

boolean = true

If false, skip the recalculate() call at the end. Useful when the caller will write more data before recalculating.

RewriteFormula


moveColumns(
sheetName,
from,
to,
count): RewriteFormula;

string

number

0-based index of first column to move

number

0-based index of end-position of first column to move

number

the number of columns to move

RewriteFormula


moveRows(
sheetName,
from,
to,
count): RewriteFormula;

string

number

0-based index of first row to move

number

0-based index of end-position of first row to move

number

the number of rows to move

RewriteFormula


off(event, listener): Emitter;

Remove a specific event handler for a specified event.

string

The name of the event.

(…arguments_) => void

The specific handler function to remove.

Emitter

The Emitter instance for method chaining.

EventEmitter.off
off(event): Emitter;

Remove all event handlers for a specified event.

string

The name of the event for which to remove all handlers.

Emitter

The Emitter instance for method chaining.

EventEmitter.off
off(): Emitter;

Remove all event handlers for all events.

Emitter

The Emitter instance for method chaining.

EventEmitter.off

on(event, listener): Emitter;

Register an event handler that listens to a specified event.

string

The name of the event to listen to.

(…arguments_) => void

The function to execute when the event is emitted.

Emitter

The Emitter instance for method chaining.

EventEmitter.on

once(event, listener): Emitter;

Register a one-time event handler for a specified event.

string

The name of the event to listen to.

(…arguments_) => void

The function to execute once when the event is emitted.

Emitter

The Emitter instance for method chaining.

EventEmitter.once

removeDefinedName(name, sheetName?): boolean;

Remove a defined name (global or sheet-scoped) from the workbook. This will schedule cells depending on that name for recalculation, but will not perform that recalculation.

string

the name of the defined name to remove. It will be matched case-insensitively.

the name of a sheet the defined name is scoped to, null if it is a global defined name. It will be matched case-insensitively.

string | null

boolean

true if the name was removed, false if it did not exist (or the sheet did not exist)


removeSheet(sheetName): boolean;

Remove a sheet from the workbook.

string

the name of the sheet to delete. It will be matched case-insensitively.

boolean

true if the sheet was removed, false if it did not exist

if there are writes that have not been reset


renameSheet(currentName, newName): void;

Rename the given sheet to a new name, updating all formulas referencing it Precondition: formula parser has finished importing (formulaParserReady has resolved).

string

string

must be different from currentName

void

if no sheet exists named currentName


requireSheet(sheetName): WorkSheet;

Like getSheet, but throws if the sheet does not exist.

string

WorkSheet


reset(): void;

void


rewriteFormulas(rewriteFormula, recalcNow): number;

(formula) => string

boolean = true

If false, skip the trailing recalculate(). The caller is responsible for triggering recalculation after any additional mutations.

number

number of formulas changed


rowHeight(rowIndex, sheetName): number;

Height of the given column in the given sheet, in pixels.

number

1-based row index

string

name of the sheet in which to look up a row height

number


setColumnWidth(
sheetName,
column,
width): void;

string

number

0-based column index

number

non-negative

void

if there is no sheet with sheetName in this workbook, or if col and/or width are invalid


setDefinedName<AbortOnError>(
name,
formula,
sheet?,
abortOnError?,
validateNow?):
| DefinedName
| AbortOnError extends true ? null : never;

Add a defined name in this workbook with the given formula. If any error is detected in the formula (syntax error, or use of something we do not support), abort and return null if abortOnError is true, else go ahead and make the defined name but record the error with this.addError.

This method does not create a vertex in the dependency graph. If the graph is already built (i.e. outside initial workbook construction), the caller must call updateDependencies([dn.vertexId]) on the returned DefinedName to register its vertex and outgoing edges.

AbortOnError extends boolean = false

string

string

sheet to scope the name to, or null for workbook scope

WorkSheet | null

AbortOnError

true to return null and make no change if formula has any errors

boolean = true

set to false to skip formula validation here (caller is responsible for it then)

| DefinedName | AbortOnError extends true ? null : never


setRowHeight(
sheetName,
rowNum,
height): void;

Sets the height of a row.

One function, SUBTOTAL, may yield different results depending on whether some cells in the range belong to hidden rows or not. Therefore, if the row becomes hidden, or was hidden before this change, a recalculation of formulas referencing cells in the affected row will be required. This call will register state about that, so that the next recalculation will update formula cells as needed. It is up to the caller to make sure a recalculation is eventually triggered.

Precondition: Workbook is initialized.

string

number

0-based row index

number

non-negative

void

if there is no sheet with sheetName in this workbook, or if rowNum and/or height are invalid


toCSF(): CSFOutput;

CSFOutput


toJsf(): JSF;

Serialize this workbook to JSF (JSON Spreadsheet Format).

This is the inverse of Workbook.fromJsf, producing a JSF object that can be used to reconstruct the workbook state.

JSF

A JSF object representing this workbook


toXlsx<T>(outputType): Promise<XlsxOutputMap[T]>;

Convert this workbook to XLSX format and return the result as a Buffer.

This method converts the workbook to JSF format first, then generates an XLSX file from that representation.

T extends keyof XlsxOutputMap = "nodebuffer"

T = ...

The output format: 'nodebuffer' (default) or 'arraybuffer'

Promise<XlsxOutputMap[T]>

A Buffer containing the XLSX file data


toXlsxFile(path): Promise<void>;

Convert this workbook to XLSX format and write it to a file.

This method converts the workbook to JSF format first, then generates an XLSX file from that representation and writes it to the specified path.

string

The file path to write the XLSX file to

Promise<void>


unmergeCells(sheetName, rangeStr): void;

Unmerge cells on the given sheet. Any existing merge that overlaps the given range is fully removed. If no merges overlap, this is a no-op.

string

name of the sheet

string

range in A1 notation, e.g. “A1:B2”

void

if the sheet does not exist


write(
ref,
val,
neutralizeFormulaOnSingleCellWrite?): boolean;

Write the given value to the given cell (A1 address or global name)

Precondition: Workbook must be initialized

the address or global name to write to

string | Reference

CellValue

the value to write

boolean = false

set to true if writes to single formula cells should neutralize them

boolean

true if a write occurred


writeCellData(cellRef, cellData):
| Cell
| DefinedName;

Write the given cell data attributes (.v, .f, etc.) to an existing or new cell.

If cell value is an error value, normalize it to the corresponding singleton error value in errorTable.

If cellData has a formula, it is parsed and (if parsing succeeds) the AST is stored in the cell object.

If cellData has an .f attribute (whether null or not), the whole workbook’s dependency graph is rebuilt (unless you pass false for rebuildDependencyGraph).

Preconditions:

  • Formula parser has finished importing (formulaParserReady has resolved).
  • Workbook must be initialized.

the cell to write, as a Reference or a string representing one. If this indicates a range, the top-left cell of that range is written. This must not be a name reference as this method does not support those yet.

string | Reference

Omit<Cell, "s" | "f" | "v"> & object & object & object

object with attributes to write to the cell

| Cell | DefinedName

the existing or new Cell instance.

if precondition is not satisfied (the formula parser has not finished importing), or if a string is passed and it fails to parse as a Reference.


writes(): [string, CellValue][];

Precondition: Workbook must be initialized

[string, CellValue][]


static fromCsf(
csf,
model,
options): Workbook;

Create a Workbook from CSF format directly, bypassing JSF conversion. This provides significantly better performance than converting CSF→JSF→Workbook.

WorkbookCSF

Workbook data in CSF format

Model

The Model instance to attach this workbook to

WorkbookOptions = {}

Workbook initialization options

Workbook

A new Workbook instance populated from CSF


static fromJsf(
jsf,
model,
options): Workbook;

Create a Workbook from JSF format.

JSF

Workbook data in JSF format

Model

The Model instance to attach this workbook to

WorkbookOptions = {}

Workbook initialization options

Workbook

A new Workbook instance populated from JSF


static fromXlsx(
data,
model,
filename,
options?): Promise<Workbook>;

Create a Workbook from XLSX binary data.

This is a convenience method that wraps @borgar/xlsx-convert to load XLSX data directly into a Workbook without requiring users to manually import the conversion library.

Note: This creates only the main workbook. External references in the XLSX file are not automatically added to the model. Use Model.addWorkbookFromXlsx to also add externals.

Binary XLSX data (works in browsers and Node.js)

ArrayBuffer | Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike>

Model

The Model instance to attach this workbook to

string

Filename to associate with the workbook

WorkbookOptions

Workbook initialization options

Promise<Workbook>

A Promise resolving to a new Workbook instance


static fromXlsxFile(
path,
model,
options?): Promise<Workbook>;

Create a Workbook from an XLSX file path.

This is a convenience method that wraps @borgar/xlsx-convert to load XLSX files directly into a Workbook without requiring users to manually import the conversion library.

Note: This creates only the main workbook. External references in the XLSX file are not automatically added to the model. Use Model.addWorkbookFromXlsxFile to also add externals.

string

Path to the XLSX file (Node.js only - uses fs)

Model

The Model instance to attach this workbook to

WorkbookOptions

Workbook initialization options

Promise<Workbook>

A Promise resolving to a new Workbook instance