Skip to content
Cellatrix

Model

Represents a spreadsheet model containing one or more workbooks.

new Model(): Model;

Model

PropertyModifierType
workbookspublicWorkbook[]
preconditionsstaticPromise<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.

ParameterTypeDescription
jsfWorkbookThe 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.

ParameterTypeDescription
data| ArrayBuffer | Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike>Binary XLSX data (works in browsers and Node.js).
filenamestringFilename to associate with the workbook.
optionsAddWorkbookOptionsConfiguration 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.

ParameterTypeDescription
pathstringPath to the XLSX file.
optionsAddWorkbookOptionsConfiguration 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.

ParameterTypeDescription
workbookName?string | nullThe name of the workbook to get.

Workbook | null


readCell(formula: string): Cell | null;

Read a cell from the model.

ParameterTypeDescription
formulastringA reference or an expression to evaluate.

Cell | null


readCells(formula: string): CellArray;

Read a 2D array of cells from the model.

ParameterTypeDescription
formulastringA 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!

ParameterTypeDescription
formulastringThe formula to run.

ReturnValue


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

Convert a workbook in the model into a JSF object.

ParameterTypeDescription
workbookName?stringThe 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.

ParameterTypeDefault valueDescription
formulastringundefinedA reference to a cell.
valueCellValueundefinedThe new value.
doRecalc?booleantrueShould 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.

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

ParameterTypeDescription
jsfWorkbookA JSF workbook structure.
optionsAddWorkbookOptionsConfiguration 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.

ParameterTypeDescription
data| ArrayBuffer | Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike>Binary XLSX data (works in browsers and Node.js).
filenamestringFilename to associate with the workbook.
optionsAddWorkbookOptionsConfiguration 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.

ParameterTypeDescription
pathstringPath to the XLSX file.
optionsAddWorkbookOptionsConfiguration 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)');