Model
Represents a spreadsheet model containing one or more workbooks.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Model(): Model;Returns
Section titled “Returns”Model
Properties
Section titled “Properties”| Property | Modifier | Type |
|---|---|---|
workbooks | public | Workbook[] |
preconditions | static | Promise<boolean> |
Accessors
Section titled “Accessors”hasData
Section titled “hasData”Get Signature
Section titled “Get Signature”get hasData(): boolean;Returns
Section titled “Returns”boolean
Methods
Section titled “Methods”addWorkbook()
Section titled “addWorkbook()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
jsf | Workbook | The JSF workbook structure to add. |
Returns
Section titled “Returns”void
getWorkbook()
Section titled “getWorkbook()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
workbookName? | string | null | The name of the workbook to get. |
Returns
Section titled “Returns”Workbook | null
readCell()
Section titled “readCell()”readCell(formula: string): Cell | null;Read a cell from the model.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
formula | string | A reference or an expression to evaluate. |
Returns
Section titled “Returns”Cell | null
readCells()
Section titled “readCells()”readCells(formula: string): CellArray;Read a 2D array of cells from the model.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
formula | string | A reference or an expression to evaluate. |
Returns
Section titled “Returns”recalculate()
Section titled “recalculate()”recalculate(): void;Pretend to recalculate the model.
WARNING: This just bumps the lastWrite counter allowing it to be used for cache invalidation.
Returns
Section titled “Returns”void
reset()
Section titled “reset()”reset(): void;Pretend to reset the model to its initial state.
WARNING: This is a no-op. The model will remain unchanged.
Returns
Section titled “Returns”void
runFormula()
Section titled “runFormula()”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!
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
formula | string | The formula to run. |
Returns
Section titled “Returns”ReturnValue
toJSF()
Section titled “toJSF()”toJSF(workbookName?: string): Workbook | null;Convert a workbook in the model into a JSF object.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
workbookName? | string | The name of the workbook to convert. If null, the first workbook is used. |
Returns
Section titled “Returns”Workbook | null
write()
Section titled “write()”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.
Parameters
Section titled “Parameters”| 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? |
Returns
Section titled “Returns”void
writeMultiple()
Section titled “writeMultiple()”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.
Parameters
Section titled “Parameters”| 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 | - |
Returns
Section titled “Returns”void
writes()
Section titled “writes()”writes(): [string, CellValue][];Get a list of all writes that have been performed on the model.
Returns
Section titled “Returns”[string, CellValue][]
A list of [cellId, value] pairs.
empty()
Section titled “empty()”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.
Returns
Section titled “Returns”Model
fromCsf()
Section titled “fromCsf()”static fromCsf(): void;Returns
Section titled “Returns”void
fromJSF()
Section titled “fromJSF()”static fromJSF(jsf: Workbook, options?: { externals?: boolean;}): Model;Create a model from a JSF structure.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
jsf | Workbook | A JSF workbook structure. |
options | { externals?: boolean; } | - |
options.externals? | boolean | - |
Returns
Section titled “Returns”Model