Skip to content

Workbook

65 methods

markClean

void
markClean(): void;

Reset the dirty flag (call after a successful save).

getSheet

Promise<Worksheet>
getSheet(name: string): Promise<Worksheet>;
ParameterTypeRequired
namestringrequired

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

Worksheet
getSheetById(sheetId: SheetId): Worksheet;
ParameterTypeRequired
sheetIdSheetIdrequired

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>;
ParameterTypeRequired
namestringrequired

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>;
ParameterTypeRequired
indexnumberrequired

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;
    }>;
ParameterTypeRequired
namestringrequired

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>;
ParameterTypeRequired
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>;
ParameterTypeRequired
labelstringrequired
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

string
createCheckpoint(label?: string): string;
ParameterTypeRequired
labelstringoptional

Create a named checkpoint (version snapshot). Returns the checkpoint ID.

restoreCheckpoint

Promise<void>
restoreCheckpoint(id: string): Promise<void>;
ParameterTypeRequired
idstringrequired

Restore the workbook to a previously saved checkpoint.

listCheckpoints

CheckpointInfo[]
listCheckpoints(): CheckpointInfo[];

List all saved checkpoints.

calculate

Promise<CalculateResult>
calculate(options?: CalculateOptions): Promise<CalculateResult>;
ParameterTypeRequired
optionsCalculateOptionsoptional

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>;
ParameterTypeRequired
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>;
ParameterTypeRequired
valuebooleanrequired

Set whether to use displayed precision. Convenience mutator — inverts and patches `calculationSettings.fullPrecision`.

on

CallableDisposable
on(event: string, handler: (event: unknown) => void): CallableDisposable;
ParameterTypeRequired
eventstringrequired
handler(event: unknown) => voidrequired

Subscribe to an arbitrary event string. Handler receives unknown payload.

executeCode

Promise<CodeResult>
executeCode(code: string, options?: ExecuteOptions): Promise<CodeResult>;
ParameterTypeRequired
codestringrequired
optionsExecuteOptionsoptional

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 | null
getFunctionInfo(name: string): FunctionInfo | null;
ParameterTypeRequired
namestringrequired

Get detailed info about a specific function.

describeRanges

Promise<SheetRangeDescribeResult[]>
describeRanges(requests: SheetRangeRequest[], includeStyle?: boolean): Promise<SheetRangeDescribeResult[]>;
ParameterTypeRequired
requestsSheetRangeRequest[]required
includeStylebooleanoptional

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[]>;
ParameterTypeRequired
datastring | Uint8Arrayrequired
optionsInsertWorksheetOptionsoptional

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>;
ParameterTypeRequired
pathstringrequired

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>;
ParameterTypeRequired
sheetWorksheet | stringrequired
rangestringrequired
optionsScreenshotOptionsoptional

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>;
ParameterTypeRequired
sourceWorkbookrequired
fromRangestringrequired
toRangestringrequired
options{ fromSheet?: string | Worksheet; toSheet?: string | Worksheet; }optional

Copy a range from another workbook into this workbook.

indexToAddress

string
indexToAddress(row: number, col: number): string;
ParameterTypeRequired
rownumberrequired
colnumberrequired

Convert row/col to A1 address: (0, 0) -> "A1"

addressToIndex

{ row: number; col: number; }
addressToIndex(address: string): {
        row: number;
        col: number;
    };
ParameterTypeRequired
addressstringrequired

Convert A1 address to row/col: "A1" -> { row: 0, col: 0 }

union

string
union(...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;
    }>>;
ParameterTypeRequired
patternsstring[]required
optionsSearchOptionsoptional

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>;
ParameterTypeRequired
valuebooleanrequired

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>;
ParameterTypeRequired
updatesPartial<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>;
ParameterTypeRequired
inputWorkbookCustomListInputrequired

Add a user-defined custom fill/sort list.

updateCustomList

Promise<boolean>
updateCustomList(id: string, updates: WorkbookCustomListUpdate): Promise<boolean>;
ParameterTypeRequired
idstringrequired
updatesWorkbookCustomListUpdaterequired

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>;
ParameterTypeRequired
idstringrequired

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>;
ParameterTypeRequired
listsreadonly 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>;
ParameterTypeRequired
keystringrequired

Get a custom setting value by key. Returns null if not found.

setCustomSetting

Promise<void>
setCustomSetting(key: string, value: string): Promise<void>;
ParameterTypeRequired
keystringrequired
valuestringrequired

Set a custom setting value.

deleteCustomSetting

Promise<void>
deleteCustomSetting(key: string): Promise<void>;
ParameterTypeRequired
keystringrequired

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>;
ParameterTypeRequired
closeBehavior'save' | 'skipSave'optional

Close the workbook with optional save behavior. @param closeBehavior - 'save' exports snapshot before disposing, 'skipSave' disposes immediately (default: 'skipSave')

dispose

void
dispose(): 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; } | null
getActiveCell(): {
        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 | null
getSelectedRange(): string | null;

Primary selected range. Returns null in headless.

getActiveChart

string | null
getActiveChart(): string | null;

Active chart object ID, or null.

getActiveShape

string | null
getActiveShape(): string | null;

Active shape object ID, or null.

getActiveSlicer

string | null
getActiveSlicer(): string | null;

Active slicer object ID, or null.

setActivePrincipal

Promise<void>
setActivePrincipal(principal: string[] | AccessPrincipal | null): Promise<void>;
ParameterTypeRequired
principalstring[] | AccessPrincipal | nullrequired

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>;
ParameterTypeRequired
tagsstring[]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.