Skip to content

api/book Functions

Functions exported from src/api/book.ts

addCellComment

function addCellComment(cell: CellObject, text: string, author?: string): void

Parameters

NameTypeDescription
cellCellObjectThe cell object to modify
textstringThe comment text content
author (optional)stringOptional author name (defaults to "SheetJS")

appendSheet

function appendSheet(wb: WorkBook, ws: WorkSheet, name?: string, roll?: boolean): string

Parameters

NameTypeDescription
wbWorkBookThe workbook to add the sheet to
wsWorkSheetThe worksheet to append
name (optional)stringOptional sheet name; auto-generated if omitted
roll (optional)booleanIf true, auto-increment the name suffix on collision instead of throwing

Returns

string

The final sheet name that was used


createSheet

function createSheet(opts?: { dense?: boolean }): WorkSheet

Parameters

NameTypeDescription
opts (optional){ dense?: boolean }Optional settings; set dense: true for dense storage mode (array-of-arrays backing)

Returns

WorkSheet

A new empty worksheet object


createWorkbook

function createWorkbook(ws?: WorkSheet, wsname?: string): WorkBook

Parameters

NameTypeDescription
ws (optional)WorkSheetOptional worksheet to include as the first sheet
wsname (optional)stringName for the initial sheet (defaults to "Sheet1")

Returns

WorkBook

A new workbook object


getSheetIndex

function getSheetIndex(wb: WorkBook, sh: string | number): number

Parameters

NameTypeDescription
wbWorkBookThe workbook to search
sh`stringnumber`

Returns

number

The zero-based sheet index


setArrayFormula

function setArrayFormula(ws: WorkSheet, range: string | { s: { r: number; c: number }; e: { r: number; c: number } }, formula: string, dynamic?: boolean): WorkSheet

Parameters

NameTypeDescription
wsWorkSheetThe worksheet to modify
range`string{ s: { r: number; c: number }; e: { r: number; c: number } }`
formulastringThe array formula expression (without surrounding braces)
dynamic (optional)booleanIf true, mark as a dynamic array formula (spill)

Returns

WorkSheet

The modified worksheet


setCellHyperlink

function setCellHyperlink(cell: CellObject, target?: string, tooltip?: string): CellObject

Parameters

NameTypeDescription
cellCellObjectThe cell object to modify
target (optional)stringThe hyperlink URL or path; falsy to remove
tooltip (optional)stringOptional tooltip text shown on hover

Returns

CellObject

The same cell object, for chaining


setCellInternalLink

function setCellInternalLink(cell: CellObject, range: string, tooltip?: string): CellObject

Parameters

NameTypeDescription
cellCellObjectThe cell object to modify
rangestringThe target cell reference or range string (e.g.
tooltip (optional)stringOptional tooltip text shown on hover

Returns

CellObject

The same cell object, for chaining


setCellNumberFormat

function setCellNumberFormat(cell: CellObject, fmt: string | number): CellObject

Parameters

NameTypeDescription
cellCellObjectThe cell object to modify
fmt`stringnumber`

Returns

CellObject

The same cell object, for chaining


setSheetVisibility

function setSheetVisibility(wb: WorkBook, sh: string | number, vis: 0 | 1 | 2): void

Parameters

NameTypeDescription
wbWorkBookThe workbook containing the sheet
sh`stringnumber`
vis`01

sheetToFormulae

function sheetToFormulae(ws: WorkSheet): string[]

Parameters

NameTypeDescription
wsWorkSheetThe worksheet to extract formulas from

Returns

string[]

An array of "ref=value" strings representing every non-empty cell