API reference

Workbook

Workbook root model: sheets, defined names, properties, calc settings.

44 exports · 12 source files

Workbook

src/workbook/workbook.ts

# addChartsheet function

src/workbook/workbook.ts:411

Add a Chartsheet to the Workbook. Returns the chartsheet for further population.

function addChartsheet(wb: Workbook, title: string, opts?: { chart?: ChartReference; index?: number; state?: SheetState }): Chartsheet

Parameters

NameTypeDescription
wb Workbook
title string
opts? { chart?: ChartReference; index?: number; state?: SheetState }

Returns

Chartsheet

# addWorksheet function

src/workbook/workbook.ts:287

Add a Worksheet to the Workbook. Returns the sheet for further population.

function addWorksheet(wb: Workbook, title: string, opts?: { index?: number; state?: SheetState }): Worksheet

Parameters

NameTypeDescription
wb Workbook
title string
opts? { index?: number; state?: SheetState }

Returns

Worksheet

# createWorkbook function

src/workbook/workbook.ts:189

Build an empty Workbook ready to host worksheets.

function createWorkbook(opts?: { date1904?: boolean }): Workbook

Parameters

NameTypeDescription
opts? { date1904?: boolean }

Returns

Workbook

# describeWorkbook function

src/workbook/workbook.ts:884
function describeWorkbook(wb: Workbook): WorkbookOverview

Parameters

NameTypeDescription
wb Workbook

Returns

WorkbookOverview

# getActiveSheet function

src/workbook/workbook.ts:1326

Currently active sheet (worksheet only), or undefined if the active slot is empty or a chartsheet.

function getActiveSheet(wb: Workbook): Worksheet | undefined

Parameters

NameTypeDescription
wb Workbook

Returns

Worksheet | undefined

# getCellAtAddress function

src/workbook/workbook.ts:793

Resolve a sheet-qualified A1 address (`'Sheet1!A1'`) to its Cell, or `undefined` when the cell isn't materialised. Throws on malformed addresses, missing sheets, or range inputs.

function getCellAtAddress(wb: Workbook, address: string): Cell | undefined

Parameters

NameTypeDescription
wb Workbook
address string

Returns

Cell | undefined

# getCellSummary function

src/workbook/workbook.ts:999
function getCellSummary(wb: Workbook, sheetTitle: string, ref: string): CellSummary

Parameters

NameTypeDescription
wb Workbook
sheetTitle string
ref string

Returns

CellSummary

# getChartsheet function

src/workbook/workbook.ts:403

Look up a Chartsheet by title. Returns undefined for missing names or worksheets.

function getChartsheet(wb: Workbook, title: string): Chartsheet | undefined

Parameters

NameTypeDescription
wb Workbook
title string

Returns

Chartsheet | undefined

# getSheet function

src/workbook/workbook.ts:389

Look up a Worksheet by title. Returns undefined for missing names or chartsheets.

function getSheet(wb: Workbook, title: string): Worksheet | undefined

Parameters

NameTypeDescription
wb Workbook
title string

Returns

Worksheet | undefined

# getSheetState function

src/workbook/workbook.ts:514

Look up the current visibility state. Throws on unknown title.

function getSheetState(wb: Workbook, title: string): SheetState

Parameters

NameTypeDescription
wb Workbook
title string

Returns

SheetState

# getWorkbookCellsByKind function

src/workbook/workbook.ts:761

Workbook-wide value-kind histogram. Sums countCellsByKind across every Worksheet (chartsheets contribute no cells). Buckets have the same shape as the per-worksheet result; an empty workbook returns all-zero counts.

function getWorkbookCellsByKind(wb: Workbook): CellsByKindCounts

Parameters

NameTypeDescription
wb Workbook

Returns

CellsByKindCounts

# getWorkbookStats function

src/workbook/workbook.ts:715
function getWorkbookStats(wb: Workbook): WorkbookStats

Parameters

NameTypeDescription
wb Workbook

Returns

WorkbookStats

# iterWorksheets function

src/workbook/workbook.ts:1045

Iterate over every Worksheet in the workbook (skips chartsheets). Yields each worksheet in tab-strip order.

function iterWorksheets(wb: Workbook): IterableIterator<Worksheet>

Parameters

NameTypeDescription
wb Workbook

Returns

IterableIterator<Worksheet>

# listCustomXmlParts function

src/workbook/workbook.ts:1353

Read-only view onto the customXml/* pass-through parts.

function listCustomXmlParts(wb: Workbook): { content: Uint8Array; path: string }[]

Parameters

NameTypeDescription
wb Workbook

Returns

{ content: Uint8Array; path: string }[]

# moveSheet function

src/workbook/workbook.ts:572

Move a sheet to a new tab-strip position. `toIndex` is clamped to `[0, sheets.length - 1]`. Adjusts `activeSheetIndex` so the same sheet stays active across the move.

function moveSheet(wb: Workbook, title: string, toIndex: number): void

Parameters

NameTypeDescription
wb Workbook
title string
toIndex number

Returns

void

# removeSheet function

src/workbook/workbook.ts:450

Remove a sheet by title. No-op if the title is not registered.

function removeSheet(wb: Workbook, title: string): void

Parameters

NameTypeDescription
wb Workbook
title string

Returns

void

# renameSheet function

src/workbook/workbook.ts:472

Rename a sheet from `oldTitle` to `newTitle`. Throws if no sheet matches `oldTitle`, or if `newTitle` collides with an existing sheet (Excel requires sheet names to be unique within a workbook).

function renameSheet(wb: Workbook, oldTitle: string, newTitle: string): void

Parameters

NameTypeDescription
wb Workbook
oldTitle string
newTitle string

Returns

void

# setActiveSheet function

src/workbook/workbook.ts:461

Set the active sheet by title; throws on unknown title.

function setActiveSheet(wb: Workbook, title: string): void

Parameters

NameTypeDescription
wb Workbook
title string

Returns

void

# setCellAtAddress function

src/workbook/workbook.ts:812

Set a single cell by sheet-qualified A1 address. Throws on malformed addresses, missing sheets, or range inputs.

function setCellAtAddress(wb: Workbook, address: string, value: CellValue): Cell

Parameters

NameTypeDescription
wb Workbook
address string
value CellValue

Returns

Cell

# setSheetState function

src/workbook/workbook.ts:490

Set the visibility state on a sheet by title. Throws on unknown title. Refuses to hide the last visible sheet: an .xlsx with every sheet hidden fails to open in Excel ("Excel cannot use the object linking and embedding features because no sheet is visible"). Catching it here keeps the workbook recoverable instead of producing a save Excel will reject.

function setSheetState(wb: Workbook, title: string, state: SheetState): void

Parameters

NameTypeDescription
wb Workbook
title string
state SheetState

Returns

void

# sheetNames function

src/workbook/workbook.ts:445

All worksheet titles, in display order.

function sheetNames(wb: Workbook): string[]

Parameters

NameTypeDescription
wb Workbook

Returns

string[]

Defined names

src/workbook/defined-names.ts

# addDefinedName function

src/workbook/defined-names.ts:59

Add a workbook-scope or sheet-scope defined name. If a defined name with the same `name` (and `scope`) already exists, it's replaced — Excel allows one workbook-scope and one per-sheet-scope name, but not two with the same scope. Returns the resulting `DefinedName`.

function addDefinedName(wb: Workbook, opts: Partial<DefinedName> & { name: string; value: string }): DefinedName

Parameters

NameTypeDescription
wb Workbook
opts Partial<DefinedName> & { name: string; value: string }

Returns

DefinedName

# getDefinedName function

src/workbook/defined-names.ts:115

Look up a defined name by identifier and (optional) sheet scope.

function getDefinedName(wb: Workbook, name: string, scope?: number): DefinedName | undefined

Parameters

NameTypeDescription
wb Workbook
name string
scope? number

Returns

DefinedName | undefined

# getDefinedNameTarget function

src/workbook/defined-names.ts:131

Resolve a defined name's `value` into one or more DefinedNameTargets. Comma-separated values (e.g. `_xlnm.Print_Titles` typically sets `Sheet!$1:$1,Sheet!$A:$A`) yield one entry per leg; a plain `Sheet!A1:B5` yields a single-element array. Returns `undefined` when the name doesn't exist; throws when the value can't be parsed (e.g. a constant or a non-range formula — defined names are sometimes used for things like `=42` or `=SUM(A:A)` which aren't ranges).

function getDefinedNameTarget(wb: Workbook, name: string, scope?: number): DefinedNameTarget[] | undefined

Parameters

NameTypeDescription
wb Workbook
name string
scope? number

Returns

DefinedNameTarget[] | undefined

# listDefinedNames function

src/workbook/defined-names.ts:185

Read-only snapshot of every defined name. Pass `{ scope }` to narrow to workbook-scope (`scope: undefined`) or one specific sheet (`scope: 0`) — omit the option entirely to list all.

function listDefinedNames(wb: Workbook, opts?: { scope?: number | "all" | "workbook" }): readonly DefinedName[]

Parameters

NameTypeDescription
wb Workbook
opts? = {}{ scope?: number | "all" | "workbook" }

Returns

readonly DefinedName[]

# makeDefinedName function

src/workbook/defined-names.ts:25
function makeDefinedName(opts: Partial<DefinedName> & { name: string; value: string }): DefinedName

Parameters

NameTypeDescription
opts Partial<DefinedName> & { name: string; value: string }

Returns

DefinedName

# removeDefinedName function

src/workbook/defined-names.ts:173

Remove a defined name by identifier + scope. Returns true if any entry was removed.

function removeDefinedName(wb: Workbook, name: string, scope?: number): boolean

Parameters

NameTypeDescription
wb Workbook
name string
scope? number

Returns

boolean

Shared strings

src/workbook/shared-strings.ts

# addSharedString function

src/workbook/shared-strings.ts:51

Insert a string and return its index. Idempotent: calling with the same value twice gives the same index. Empty strings are deduped just like everything else.

function addSharedString(table: SharedStringsTable, value: string): number

Parameters

NameTypeDescription
table SharedStringsTable
value string

Returns

number

# getSharedStringAt function

src/workbook/shared-strings.ts:71

Read a shared-string by its 0-based index. Returns `undefined` for out-of-range. Rich-text entries surface their concatenated plain text so callers that want only the textual body don't need to know about the discriminated union.

function getSharedStringAt(table: SharedStringsTable, index: number): string | undefined

Parameters

NameTypeDescription
table SharedStringsTable
index number

Returns

string | undefined

# getSharedStringIndex function

src/workbook/shared-strings.ts:61

Look up a shared-string index by its literal text. Returns `undefined` for unknown values.

function getSharedStringIndex(table: SharedStringsTable, value: string): number | undefined

Parameters

NameTypeDescription
table SharedStringsTable
value string

Returns

number | undefined

# makeSharedStrings function

src/workbook/shared-strings.ts:42
function makeSharedStrings(): SharedStringsTable

Returns

SharedStringsTable

# sharedStringCount function

src/workbook/shared-strings.ts:79

Number of unique entries in the SST.

function sharedStringCount(table: SharedStringsTable): number

Parameters

NameTypeDescription
table SharedStringsTable

Returns

number

Function groups

src/workbook/function-groups.ts

# makeFunctionGroup function

src/workbook/function-groups.ts:18
function makeFunctionGroup(name: string): FunctionGroup

Parameters

NameTypeDescription
name string

Returns

FunctionGroup

# makeFunctionGroups function

src/workbook/function-groups.ts:20
function makeFunctionGroups(opts?: Partial<FunctionGroups>): FunctionGroups

Parameters

NameTypeDescription
opts? = {}Partial<FunctionGroups>

Returns

FunctionGroups

Smart tags

src/workbook/smart-tags.ts

# makeSmartTagProperties function

src/workbook/smart-tags.ts:20
function makeSmartTagProperties(opts?: SmartTagProperties): SmartTagProperties

Parameters

NameTypeDescription
opts? = {}SmartTagProperties

Returns

SmartTagProperties

# makeSmartTagType function

src/workbook/smart-tags.ts:22
function makeSmartTagType(opts?: SmartTagType): SmartTagType

Parameters

NameTypeDescription
opts? = {}SmartTagType

Returns

SmartTagType

Views

src/workbook/views.ts

# makeCustomWorkbookView function

src/workbook/views.ts:66
function makeCustomWorkbookView(opts: Pick<CustomWorkbookView, "guid" | "name" | "windowWidth" | "windowHeight" | "activeSheetId"> & Partial<CustomWorkbookView>): CustomWorkbookView

Parameters

NameTypeDescription
opts Pick<CustomWorkbookView, "guid" | "name" | "windowWidth" | "windowHeight" | "activeSheetId"> & Partial<CustomWorkbookView>

Returns

CustomWorkbookView

# makeWorkbookView function

src/workbook/views.ts:31
function makeWorkbookView(opts?: WorkbookView): WorkbookView

Parameters

NameTypeDescription
opts? = {}WorkbookView

Returns

WorkbookView

Calc properties

src/workbook/calc-properties.ts

# makeCalcProperties function

src/workbook/calc-properties.ts:34
function makeCalcProperties(opts?: CalcProperties): CalcProperties

Parameters

NameTypeDescription
opts? = {}CalcProperties

Returns

CalcProperties

File recovery

src/workbook/file-recovery.ts

# makeFileRecoveryProperties function

src/workbook/file-recovery.ts:18
function makeFileRecoveryProperties(opts?: FileRecoveryProperties): FileRecoveryProperties

Parameters

NameTypeDescription
opts? = {}FileRecoveryProperties

Returns

FileRecoveryProperties

File sharing

src/workbook/file-sharing.ts

# makeFileSharing function

src/workbook/file-sharing.ts:21
function makeFileSharing(opts?: FileSharing): FileSharing

Parameters

NameTypeDescription
opts? = {}FileSharing

Returns

FileSharing

File version

src/workbook/file-version.ts

# makeFileVersion function

src/workbook/file-version.ts:20
function makeFileVersion(opts?: FileVersion): FileVersion

Parameters

NameTypeDescription
opts? = {}FileVersion

Returns

FileVersion

Protection

src/workbook/protection.ts

# makeWorkbookProtection function

src/workbook/protection.ts:37
function makeWorkbookProtection(opts?: WorkbookProtection): WorkbookProtection

Parameters

NameTypeDescription
opts? = {}WorkbookProtection

Returns

WorkbookProtection

Workbook properties

src/workbook/workbook-properties.ts

# makeWorkbookProperties function

src/workbook/workbook-properties.ts:44
function makeWorkbookProperties(opts?: WorkbookProperties): WorkbookProperties

Parameters

NameTypeDescription
opts? = {}WorkbookProperties

Returns

WorkbookProperties