Skip to content

api/book Functions

Functions from src/api/book.ts

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


freezePanes

function freezePanes(ws: WorkSheet, pane: { xSplit?: number; ySplit?: number }): WorkSheet

Parameters

NameTypeDescription
wsWorkSheet-
pane{ xSplit?: number; ySplit?: number }-

Returns

WorkSheet


getSheetIndex

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

Parameters

NameTypeDescription
wbWorkBookThe workbook to search
sh`stringnumber`

Returns

number

The zero-based sheet index


mergeCells

function mergeCells(ws: WorkSheet, range: string | Range): WorkSheet

Parameters

NameTypeDescription
wsWorkSheet-
range`stringRange`

Returns

WorkSheet


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


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


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


setCellStyle

function setCellStyle(cell: CellObject, style: CellStyle): CellObject

Parameters

NameTypeDescription
cellCellObject-
styleCellStyle-

Returns

CellObject


setColumnWidth

function setColumnWidth(ws: WorkSheet, col: number, width: number): WorkSheet

Parameters

NameTypeDescription
wsWorkSheet-
colnumber-
widthnumber-

Returns

WorkSheet


setRowHeight

function setRowHeight(ws: WorkSheet, row: number, hpt: number): WorkSheet

Parameters

NameTypeDescription
wsWorkSheet-
rownumber-
hptnumber-

Returns

WorkSheet


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, opts?: WorksheetCellBudgetOptions): string[]

Parameters

NameTypeDescription
wsWorkSheetThe worksheet to extract formulas from
opts (optional)WorksheetCellBudgetOptionsOptional worksheet export budget

Returns

string[]

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


styleRange

function styleRange(ws: WorkSheet, range: string | Range, style: CellStyle, opts?: { createCells?: boolean }): WorkSheet

Parameters

NameTypeDescription
wsWorkSheet-
range`stringRange`
styleCellStyle-
opts (optional){ createCells?: boolean }-

Returns

WorkSheet