Skip to content

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): void;

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.

void


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?: {
externals?: boolean;
}): Model;

Create a model from a JSF structure.

ParameterTypeDescription
jsfWorkbookA JSF workbook structure.
options{ externals?: boolean; }-
options.externals?boolean-

Model