Skip to content
Cellatrix

Model

Represents a spreadsheet model containing one or more workbooks.

new Model(): Model;

Model

Property Modifier Type
workbooks public Workbook[]
preconditions static Promise<boolean>
get hasData(): boolean;

boolean

addWorkbook(jsf: Workbook): Workbook;

Adds a workbook into the model.

The model will accept any amount of workbooks, but most operations only support the first one added.

Parameter Type Description
jsf Workbook The JSF workbook structure to add.

Workbook

The Workbook that was created and added.


addWorkbookFromXLSX(
data:
| ArrayBuffer
| Buffer<ArrayBufferLike>
| Uint8Array<ArrayBufferLike>,
filename: string,
options?: AddWorkbookOptions
): Promise<Workbook>;

Add a workbook from XLSX binary data.

This is a convenience method that wraps @borgar/xlsx-convert to load XLSX data directly into the model, so callers do not need to install or invoke the conversion library themselves. External references in the XLSX are also added to the model.

Parameter Type Description
data | ArrayBuffer | Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike> Binary XLSX data (works in browsers and Node.js).
filename string Filename to associate with the workbook.
options? AddWorkbookOptions Configuration options for workbook initialization.

Promise<Workbook>

A Promise resolving to the loaded Workbook.


addWorkbookFromXLSXFile(path: string, options?: AddWorkbookOptions): Promise<Workbook>;

Add a workbook from an XLSX file path.

This is a convenience method that wraps @borgar/xlsx-convert to load XLSX files directly into the model. Node.js only — uses fs. External references in the XLSX are also added to the model.

Parameter Type Description
path string Path to the XLSX file.
options? AddWorkbookOptions Configuration options for workbook initialization.

Promise<Workbook>

A Promise resolving to the loaded Workbook.


getWorkbook(workbookName?: string | null): Workbook | null;

Get a workbook instance from the model.

This is an incomplete method in that it will only return the first workbook added.

Parameter Type Description
workbookName? string | null The name of the workbook to get.

Workbook | null


readCell(formula: string): Cell | null;

Read a cell from the model.

Parameter Type Description
formula string A reference or an expression to evaluate.

Cell | null


readCells(formula: string): CellArray;

Read a 2D array of cells from the model.

Parameter Type Description
formula string A reference or an expression to evaluate.

CellArray


recalculate(): void;

Pretend to recalculate the model.

WARNING: This just bumps the lastWrite counter allowing it to be used for cache invalidation.

void


reset(): void;

Pretend to reset the model to its initial state.

WARNING: This is a no-op. The model will remain unchanged.

void


runFormula(formula: string): ReturnValue;

Run a formula in the model.

This is a low-level method that simply evaluates the formula and returns the raw result.

WARNING: The evaluator is VERY limited and does not support most spreadsheet functions!

Parameter Type Description
formula string The formula to run.

ReturnValue


toJSF(workbookName?: string): Workbook | null;

Convert a workbook in the model into a JSF object.

Parameter Type Description
workbookName? string The name of the workbook to convert. If null, the first workbook is used.

Workbook | null


write(
formula: string,
value: CellValue,
doRecalc?: boolean
): void;

Write a value to a cell.

WARNING: While the value does get written to the cell, dependent cells will not be updated.

Parameter Type Default value Description
formula string undefined A reference to a cell.
value CellValue undefined The new value.
doRecalc? boolean true Should the model pretend to do recalculation after the write?

void


writeMultiple(pairs: [string, CellValue][], opts?: {
forceRecalc?: boolean;
skipRecalc?: boolean;
}): void;

Perform multiple writes of value to cell.

WARNING: While the values do get written to the cells, dependent cells will not be updated.

Parameter Type Description
pairs [string, CellValue][] A list of [reference, value] pairs.
opts? { forceRecalc?: boolean; skipRecalc?: boolean; } Options for the write operation.
opts.forceRecalc? boolean -
opts.skipRecalc? boolean -

void


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

Get a list of all writes that have been performed on the model.

[string, CellValue][]

A list of [cellId, value] pairs.


static empty(): Model;

Create an “empty” Model.

A convenience method for creating a new Model from scratch without needing to provide JSF data. The returned model contains one workbook, with one worksheet named “Sheet1”, with a single empty cell.

Model


static fromCsf(): void;

void


static fromJSF(jsf: Workbook, options?: AddWorkbookOptions): Model;

Create a model from a JSF structure.

Parameter Type Description
jsf Workbook A JSF workbook structure.
options? AddWorkbookOptions Configuration options for workbook initialization.

Model


static fromXLSX(
data:
| ArrayBuffer
| Buffer<ArrayBufferLike>
| Uint8Array<ArrayBufferLike>,
filename: string,
options?: AddWorkbookOptions
): Promise<Model>;

Create a model from XLSX binary data.

This is a convenience method that wraps @borgar/xlsx-convert so callers can load an Excel file without installing or invoking the conversion library themselves.

Parameter Type Description
data | ArrayBuffer | Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike> Binary XLSX data (works in browsers and Node.js).
filename string Filename to associate with the workbook.
options? AddWorkbookOptions Configuration options for workbook initialization.

Promise<Model>

A Promise resolving to a new Model instance containing the loaded workbook.

const response = await fetch('https://example.com/budget.xlsx');
const data = await response.arrayBuffer();
const model = await Model.fromXLSX(data, 'budget.xlsx');

static fromXLSXFile(path: string, options?: AddWorkbookOptions): Promise<Model>;

Create a model from an XLSX file path.

This is a convenience method that wraps @borgar/xlsx-convert so callers can load an Excel file without installing or invoking the conversion library themselves. Node.js only — uses fs.

Parameter Type Description
path string Path to the XLSX file.
options? AddWorkbookOptions Configuration options for workbook initialization.

Promise<Model>

A Promise resolving to a new Model instance containing the loaded workbook.

const model = await Model.fromXLSXFile('budget.xlsx');
const total = model.readCell('=SUM(D:D)');