Workbook
65 methods
Sub-APIs
markClean
→ voidmarkClean(): void;Reset the dirty flag (call after a successful save).
getSheet
→ Promise<Worksheet>getSheet(name: string): Promise<Worksheet>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
Get a sheet by name (case-insensitive). ASYNC — resolves name via Rust. This is the primary sheet accessor for agents, LLMs, and app code. For internal code that already has a SheetId, use `getSheetById()`.
getSheetById
→ WorksheetgetSheetById(sheetId: SheetId): Worksheet;| Parameter | Type | Required |
|---|---|---|
| sheetId | SheetId | required |
Get a sheet by internal SheetId. SYNC — no IPC needed. Throws KernelError if not found.
findSheet
→ Promise<Worksheet | null>findSheet(name: string): Promise<Worksheet | null>;| Parameter | Type | Required |
|---|---|---|
| name | string | required |
Find a worksheet by name (case-insensitive), returning null if not found. Non-throwing alternative to {@link getSheet}. @param name - Sheet name (case-insensitive) @returns The worksheet, or null if no sheet with that name exists
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.
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
getSheets
→ Promise<Worksheet[]>getSheets(): Promise<Worksheet[]>;Get all worksheets in display order. ASYNC — resolves each sheet by name.
getSheetCount
→ Promise<number>getSheetCount(): Promise<number>;Get the count of sheets. Convenience wrapper around sheetCount property.
getSheetNames
→ Promise<string[]>getSheetNames(): Promise<string[]>;Get all sheet names in display order. Convenience wrapper around sheetNames property.
undoGroup
→ Promise<T>undoGroup<T = void>(fn: (wb: Workbook) => Promise<T>): Promise<T>;| Parameter | Type | Required |
|---|---|---|
| fn | (wb: Workbook) => Promise<T> | required |
Execute a group of operations as a single undo step. NOT transactional: if an operation throws, prior writes in the group remain committed. Each mutation within the group still triggers its own recalc pass.
batch
→ Promise<T>batch<T = void>(label: string, fn: (wb: Workbook) => Promise<T>): Promise<T>;| Parameter | Type | Required |
|---|---|---|
| label | string | required |
| fn | (wb: Workbook) => Promise<T> | required |
Execute a group of operations as a single undo step with a label. Like `undoGroup`, but attaches a human-readable label to the undo entry (e.g. "Import data"). NOT transactional: partial writes remain committed if fn throws. Each mutation still triggers its own recalc pass.
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): Promise<CalculateResult>;| Parameter | Type | Required |
|---|---|---|
| options | CalculateOptions | 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) plus `recomputedCount` — the number of formula cells recomputed during this call. @param options - Calculation options.
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`.
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`.
on
→ CallableDisposableon(event: string, handler: (event: unknown) => void): CallableDisposable;| Parameter | Type | Required |
|---|---|---|
| event | string | required |
| handler | (event: unknown) => void | required |
Subscribe to an arbitrary event string. Handler receives unknown payload.
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().
toXlsx
→ Promise<Uint8Array>toXlsx(): Promise<Uint8Array>;Export the workbook as XLSX binary data.
insertWorksheets
→ Promise<string[]>insertWorksheets(data: string | Uint8Array, options?: InsertWorksheetOptions): Promise<string[]>;| Parameter | Type | Required |
|---|---|---|
| data | string | Uint8Array | required |
| options | InsertWorksheetOptions | optional |
Import sheets from XLSX data. Accepts base64-encoded string or raw Uint8Array. Returns the names of the inserted sheets (may be deduped if names collide).
save
→ Promise<Uint8Array>save(path: string): Promise<Uint8Array>;| Parameter | Type | Required |
|---|---|---|
| path | string | required |
Save the workbook to a file path or buffer. Marks the workbook as clean.
captureScreenshot
→ Promise<Uint8Array>captureScreenshot(sheet: Worksheet | string, range: string, options?: ScreenshotOptions): Promise<Uint8Array>;| Parameter | Type | Required |
|---|---|---|
| sheet | Worksheet | string | required |
| range | string | required |
| options | ScreenshotOptions | optional |
Capture a PNG screenshot of a cell range. @param sheet - Sheet name (e.g. "Sheet1") or Worksheet instance @param range - A1-notation cell range (e.g. "A1:G10") @param options - Rendering options (DPR, headers, gridlines, max dimensions) @returns PNG image as a Buffer
copyRangeFrom
→ Promise<void>copyRangeFrom(source: Workbook, fromRange: string, toRange: string, options?: {
fromSheet?: string | Worksheet;
toSheet?: string | Worksheet;
}): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| source | Workbook | required |
| fromRange | string | required |
| toRange | string | required |
| options | { fromSheet?: string | Worksheet; toSheet?: string | Worksheet; } | optional |
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 spreadsheet special-cell typeApplication.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 '.').
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. Workbook chart data point tracking..
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.
getCustomLists
→ Promise<readonly CustomList[]>getCustomLists(): Promise<readonly CustomList[]>;Get workbook-level custom fill/sort lists. Returns the complete catalog: immutable built-in lists followed by workbook-scoped user-defined lists.
addCustomList
→ Promise<CustomList>addCustomList(input: WorkbookCustomListInput): Promise<CustomList>;| Parameter | Type | Required |
|---|---|---|
| input | WorkbookCustomListInput | required |
Add a user-defined custom fill/sort list.
updateCustomList
→ Promise<boolean>updateCustomList(id: string, updates: WorkbookCustomListUpdate): Promise<boolean>;| Parameter | Type | Required |
|---|---|---|
| id | string | required |
| updates | WorkbookCustomListUpdate | required |
Update a user-defined custom fill/sort list. Returns false when the list does not exist or is built-in.
deleteCustomList
→ Promise<boolean>deleteCustomList(id: string): Promise<boolean>;| Parameter | Type | Required |
|---|---|---|
| id | string | required |
Delete a user-defined custom fill/sort list. Returns false when the list does not exist or is built-in.
setCustomLists
→ Promise<void>setCustomLists(lists: readonly WorkbookCustomListInput[]): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| lists | readonly WorkbookCustomListInput[] | required |
Replace all user-defined custom fill/sort lists. Built-in lists are code-owned and are never persisted through this method.
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. If this workbook was created via `DocumentHandle.workbook()`, disposing also cleans up the underlying DocumentHandle (and vice versa).
[Symbol.asyncDispose]
[Symbol.asyncDispose](): Promise<void>;Async dispose for TC39 Explicit Resource Management. @example ```typescript await using wb = await createWorkbook(); ```
getActiveCell
→ { sheetId: string; row: number; col: number; address: string; } | nullgetActiveCell(): {
sheetId: string;
row: number;
col: number;
address: string;
} | 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.
setActivePrincipal
→ Promise<void>setActivePrincipal(principal: string[] | AccessPrincipal | null): Promise<void>;| Parameter | Type | Required |
|---|---|---|
| principal | string[] | AccessPrincipal | null | required |
Set the active principal for this session. Pass `null` (or an empty tag list) to clear. Semantics tied to document state, not session state: when the document has no policies, this is effectively a no-op for access decisions (the gated delegate's fast path skips the principal entirely). Once any policy exists, `null` means anonymous — a caller that never set a principal is denied, not owner. Accepts either a flat tag list or an `AccessPrincipal` envelope for symmetry with `explainAccess` / `getEffectiveAccess`.
activePrincipal
→ Promise<AccessPrincipal | null>activePrincipal(): Promise<AccessPrincipal | null>;Current active principal, or `null` if none is set.
securityActive
→ Promise<boolean>securityActive(): Promise<boolean>;Whether access-control enforcement is currently active on this document. `false` when the policy set is empty. SDKs use this to warn users who set a principal on a doc that has no policies ("you set a principal but nothing will be enforced").
makePrincipal
→ Promise<AccessPrincipal>makePrincipal(tags: string[]): Promise<AccessPrincipal>;| Parameter | Type | Required |
|---|---|---|
| tags | string[] | required |
Canonicalize a tag list through the engine's intern pool and return the canonical (sorted + deduped) form. Primary purpose is to pre-warm the pool so the next `setActivePrincipal` with the same tag set hits an existing slab — matrix-cache pointer identity stays sound on the first call post-swap.