Workbook
62 methods
Sub-APIs
markClean
→ voidmarkClean(): void;Reset the dirty flag (call after a successful save).
getSheet
→ WorksheetgetSheet(sheetId: SheetId): Worksheet;| Parameter | Type | Required |
|---|---|---|
| sheetId | SheetId | required |
Get a sheet by internal SheetId. SYNC — no IPC needed. Throws KernelError if not found.
getSheetByName
→ Promise<Worksheet>getSheetByName(name: string): Promise<Worksheet>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
Get a sheet by name (case-insensitive). ASYNC — resolves name via Rust.
getSheetByIndex
→ Promise<Worksheet>getSheetByIndex(index: number): Promise<Worksheet>;| Parameter | Type | Required |
|---|---|---|
| index | number | required |
Get a sheet by 0-based index. ASYNC — resolves index via Rust.
getActiveSheet
→ WorksheetgetActiveSheet(): Worksheet;Get the currently active sheet. SYNC — uses known activeSheetId.
getOrCreateSheet
→ Promise<{ sheet: Worksheet; created: boolean }>getOrCreateSheet(name: string): Promise<{ sheet: Worksheet; created: boolean }>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
Get a sheet by name, creating it if it doesn't exist. @param name - Sheet name (case-insensitive lookup) @returns The sheet and whether it was newly created
getSheetCount
→ Promise<number>getSheetCount(): Promise<number>;Get the number of sheets in the workbook. ASYNC — reads from Rust.
getSheetNames
→ Promise<string[]>getSheetNames(): Promise<string[]>;Get the names of all sheets in order. ASYNC — reads from Rust.
batch
→ Promise<T>batch<T = void>(fn: (wb: Workbook) => Promise<T>): Promise<T>;| Parameter | Type | Required |
|---|---|---|
| fn | (wb: Workbook) => Promise<T> | required |
Execute a batch of operations as a single undo step. All operations inside the callback are grouped into one undo step. If an operation throws, the undo group is closed and all prior writes in the batch remain committed (Excel-style best-effort, not transactional). Note: Each mutation within the batch still triggers its own recalc pass. True deferred recalculation (single recalc at batch end) is not yet implemented.
createCheckpoint
→ stringcreateCheckpoint(label?: string): string;| Parameter | Type | Required |
|---|---|---|
| label | string | optional |
Create a named checkpoint (version snapshot). Returns the checkpoint ID.
restoreCheckpoint
→ Promise<void>restoreCheckpoint(id: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| id | string | required |
Restore the workbook to a previously saved checkpoint.
listCheckpoints
→ CheckpointInfo[]listCheckpoints(): CheckpointInfo[];List all saved checkpoints.
calculate
→ Promise<CalculateResult>calculate(options?: CalculateOptions | CalculationType): Promise<CalculateResult>;| Parameter | Type | Required |
|---|---|---|
| options | CalculateOptions | CalculationType | optional |
Trigger recalculation of formulas. For circular references (common in financial models — debt schedules, tax shields), enable iterative calculation: await wb.calculate({ iterative: { maxIterations: 100, maxChange: 0.001 } }); Returns convergence metadata (hasCircularRefs, converged, iterations, maxDelta). @param options - Calculation options, or a CalculationType string for backward compatibility
getCalculationMode
→ Promise<'auto' | 'autoNoTable' | 'manual'>getCalculationMode(): Promise<'auto' | 'autoNoTable' | 'manual'>;Get the current calculation mode (auto/manual/autoNoTable). Convenience accessor — equivalent to `(await getSettings()).calculationSettings.calcMode`.
setCalculationMode
→ Promise<void>setCalculationMode(mode: 'auto' | 'autoNoTable' | 'manual'): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| mode | 'auto' | 'autoNoTable' | 'manual' | required |
Set the calculation mode. Convenience mutator — patches `calculationSettings.calcMode`.
getIterativeCalculation
→ Promise<boolean>getIterativeCalculation(): Promise<boolean>;Get whether iterative calculation is enabled for circular references. Convenience accessor — equivalent to `(await getSettings()).calculationSettings.enableIterativeCalculation`.
setIterativeCalculation
→ Promise<void>setIterativeCalculation(enabled: boolean): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| enabled | boolean | required |
Set whether iterative calculation is enabled for circular references. Convenience mutator — patches `calculationSettings.enableIterativeCalculation`. @deprecated Use calculate({ iterative: ... }) instead.
setMaxIterations
→ Promise<void>setMaxIterations(n: number): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| n | number | required |
Set the maximum number of iterations for iterative calculation. Convenience mutator — patches `calculationSettings.maxIterations`. @deprecated Use calculate({ iterative: { maxIterations: n } }) instead.
setConvergenceThreshold
→ Promise<void>setConvergenceThreshold(threshold: number): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| threshold | number | required |
Set the convergence threshold (maximum change) for iterative calculation. Convenience mutator — patches `calculationSettings.maxChange`. @deprecated Use calculate({ iterative: { maxChange: threshold } }) instead.
getUsePrecisionAsDisplayed
→ Promise<boolean>getUsePrecisionAsDisplayed(): Promise<boolean>;Whether to use displayed precision instead of full (15-digit) precision. Convenience accessor — inverted from `calculationSettings.fullPrecision`.
setUsePrecisionAsDisplayed
→ Promise<void>setUsePrecisionAsDisplayed(value: boolean): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| value | boolean | required |
Set whether to use displayed precision. Convenience mutator — inverts and patches `calculationSettings.fullPrecision`.
getCalculationEngineVersion
→ stringgetCalculationEngineVersion(): string;Get the calculation engine version string.
on
→ () => voidon(event: WorkbookEvent | string, handler: (event: any) => void): () => void;| Parameter | Type | Required |
|---|---|---|
| event | WorkbookEvent | string | required |
| handler | (event: any) => void | required |
Subscribe to a coarse WorkbookEvent or arbitrary event string. Handler receives the internal event directly.
executeCode
→ Promise<CodeResult>executeCode(code: string, options?: ExecuteOptions): Promise<CodeResult>;| Parameter | Type | Required |
|---|---|---|
| code | string | required |
| options | ExecuteOptions | optional |
Execute TypeScript/JavaScript code in the spreadsheet sandbox.
getWorkbookSnapshot
→ Promise<WorkbookSnapshot>getWorkbookSnapshot(): Promise<WorkbookSnapshot>;Get a summary snapshot of the entire workbook.
getFunctionCatalog
→ FunctionInfo[]getFunctionCatalog(): FunctionInfo[];Get the catalog of all available spreadsheet functions.
getFunctionInfo
→ FunctionInfo | nullgetFunctionInfo(name: string): FunctionInfo | null;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
Get detailed info about a specific function.
describeRanges
→ Promise<SheetRangeDescribeResult[]>describeRanges(
requests: SheetRangeRequest[],
includeStyle?: boolean,
): Promise<SheetRangeDescribeResult[]>;| Parameter | Type | Required |
|---|---|---|
| requests | SheetRangeRequest[] | required |
| includeStyle | boolean | optional |
Describe multiple ranges across multiple sheets in a single IPC call. Each entry returns the same LLM-formatted output as ws.describeRange().
exportSnapshot
→ Promise<WorkbookSnapshot>exportSnapshot(): Promise<WorkbookSnapshot>;Export the workbook as a snapshot.
toBuffer
→ Promise<Uint8Array>toBuffer(): Promise<Uint8Array>;Export the workbook as an XLSX binary buffer.
insertWorksheetsFromBase64
→ Promise<string[]>insertWorksheetsFromBase64(base64: string, options?: InsertWorksheetOptions): Promise<string[]>;| Parameter | Type | Required |
|---|---|---|
| base64 | string | required |
| options | InsertWorksheetOptions | optional |
Import sheets from an XLSX file (base64-encoded). Returns the names of the inserted sheets (may be deduped if names collide).
save
→ Promise<Uint8Array>save(): Promise<Uint8Array>;Save the workbook. Exports to XLSX, calls platform save handler if provided, marks clean. Returns the XLSX buffer.
copyRangeFrom
→ Promise<void>copyRangeFrom(source: Workbook, fromRange: string, toRange: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| source | Workbook | required |
| fromRange | string | required |
| toRange | string | required |
Copy a range from another workbook into this workbook.
indexToAddress
→ stringindexToAddress(row: number, col: number): string;| Parameter | Type | Required |
|---|---|---|
| row | number | required |
| col | number | required |
Convert row/col to A1 address: (0, 0) -> "A1"
addressToIndex
→ { row: number; col: number }addressToIndex(address: string): { row: number; col: number };| Parameter | Type | Required |
|---|---|---|
| address | string | required |
Convert A1 address to row/col: "A1" -> { row: 0, col: 0 }
union
→ stringunion(...ranges: string[]): string;Combine multiple range addresses into a single comma-separated address. Equivalent to OfficeJS Application.union().
getCultureInfo
→ Promise<CultureInfo>getCultureInfo(): Promise<CultureInfo>;Get full CultureInfo for the workbook's current culture setting. Resolves the `culture` IETF tag (e.g. 'de-DE') into a complete CultureInfo with number/date/currency formatting details.
getDecimalSeparator
→ Promise<string>getDecimalSeparator(): Promise<string>;Get the decimal separator for the current culture (e.g. '.' or ',').
getThousandsSeparator
→ Promise<string>getThousandsSeparator(): Promise<string>;Get the thousands separator for the current culture (e.g. ',' or '.').
getAllTables
→ Promise<TableInfo[]>getAllTables(): Promise<TableInfo[]>;Get all tables across all sheets.
getAllPivotTables
→ Promise<PivotTableInfo[]>getAllPivotTables(): Promise<PivotTableInfo[]>;Get all pivot tables across all sheets.
getAllSlicers
→ Promise<SlicerInfo[]>getAllSlicers(): Promise<SlicerInfo[]>;Get all slicers across all sheets.
getAllComments
→ Promise<Comment[]>getAllComments(): Promise<Comment[]>;Get all comments across all sheets.
searchAllSheets
→ Promise<Array<SearchResult & { sheetName: string }>>searchAllSheets(
patterns: string[],
options?: SearchOptions,
): Promise<Array<SearchResult & { sheetName: string }>>;| Parameter | Type | Required |
|---|---|---|
| patterns | string[] | required |
| options | SearchOptions | optional |
Search all sheets for cells matching regex patterns (single IPC call).
getChartDataPointTrack
→ Promise<boolean>getChartDataPointTrack(): Promise<boolean>;Get whether chart data points track cell movement. OfficeJS: Workbook.chartDataPointTrack (#44).
setChartDataPointTrack
→ Promise<void>setChartDataPointTrack(value: boolean): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| value | boolean | required |
Set whether chart data points track cell movement.
getSettings
→ Promise<WorkbookSettings>getSettings(): Promise<WorkbookSettings>;Get workbook-level settings.
setSettings
→ Promise<void>setSettings(updates: Partial<WorkbookSettings>): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| updates | Partial<WorkbookSettings> | required |
Update workbook-level settings.
getCustomSetting
→ Promise<string | null>getCustomSetting(key: string): Promise<string | null>;| Parameter | Type | Required |
|---|---|---|
| key | string | required |
Get a custom setting value by key. Returns null if not found.
setCustomSetting
→ Promise<void>setCustomSetting(key: string, value: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| key | string | required |
| value | string | required |
Set a custom setting value.
deleteCustomSetting
→ Promise<void>deleteCustomSetting(key: string): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| key | string | required |
Delete a custom setting by key.
listCustomSettings
→ Promise<Array<{ key: string; value: string }>>listCustomSettings(): Promise<Array<{ key: string; value: string }>>;List all custom settings as key-value pairs.
getCustomSettingCount
→ Promise<number>getCustomSettingCount(): Promise<number>;Get the number of custom settings.
close
→ Promise<void>close(closeBehavior?: 'save' | 'skipSave'): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| closeBehavior | 'save' | 'skipSave' | optional |
Close the workbook with optional save behavior. @param closeBehavior - 'save' exports snapshot before disposing, 'skipSave' disposes immediately (default: 'skipSave')
dispose
→ voiddispose(): void;Dispose of the workbook and release resources.
getActiveCell
→ { sheetId: string; row: number; col: number } | nullgetActiveCell(): { sheetId: string; row: number; col: number } | null;Active cell. Returns null in headless/no-UI contexts.
getSelectedRanges
→ string[]getSelectedRanges(): string[];Currently selected range(s) as A1 address strings. Returns [] in headless.
getSelectedRange
→ string | nullgetSelectedRange(): string | null;Primary selected range. Returns null in headless.
getActiveChart
→ string | nullgetActiveChart(): string | null;Active chart object ID, or null.
getActiveShape
→ string | nullgetActiveShape(): string | null;Active shape object ID, or null.
getActiveSlicer
→ string | nullgetActiveSlicer(): string | null;Active slicer object ID, or null.