API overview

The full TypeScript API is bundled with the npm package — your editor will autocomplete every export. This page is the map: where to look for each kind of thing.

The full, section-organized reference lives at /api — every export rendered with its signature, parameters, and source link. This page is the conceptual map you reach for first.

Subpath entries

The package has no root barrel — every export lives behind a section subpath, so your editor’s autocomplete only surfaces what’s relevant to the area you’re working in. Each export has exactly one home (no convenience re-exports).

// Load and save xlsx — loadWorkbook / saveWorkbook / workbookToBytes,
// plus byte-level Source/Sink types and browser helpers (Blob/Response/Stream).
import { loadWorkbook, saveWorkbook, fromResponse } from 'xlsx-kit/io';

// Node fs glue (filesystem / Readable / Writable bridges + Buffer source/sink).
import { fromFile, toFile, fromBuffer, fromReadable } from 'xlsx-kit/node';

// Streaming — read iter, write-only append.
import { loadWorkbookStream, createWriteOnlyWorkbook } from 'xlsx-kit/streaming';

// Workbook root model — createWorkbook, addWorksheet, defined names, etc.
import { createWorkbook, addWorksheet } from 'xlsx-kit/workbook';

// Worksheet — setCell, getCell, mergeCells, freeze panes, tables, hyperlinks…
import { setCell, mergeCells } from 'xlsx-kit/worksheet';

// Cell value-model + inline rich text.
import { makeCell, makeRichText } from 'xlsx-kit/cell';

// Styles — fonts, fills, borders, alignment, number formats, named styles.
import { makeFont, setBold } from 'xlsx-kit/styles';

// Charts (legacy `c:` + chartex `cx:`).
import { makeBarChart, makeChartSpace } from 'xlsx-kit/chart';

// Drawings — anchors, images, chart placement.
import { addImageAt, loadImage } from 'xlsx-kit/drawing';

Other available subpaths: xlsx-kit/chartsheet, xlsx-kit/packaging, xlsx-kit/utils, xlsx-kit/xml, xlsx-kit/zip, xlsx-kit/schema.

Each entry has the bundle budgets enforced by pnpm size in CI. All exports are tree-shakable — "sideEffects": false is set in package.json.

Workbook model

The library exposes a layered model split across subpaths:

  • I/O (xlsx-kit/io) — loadWorkbook, saveWorkbook, workbookToBytes plus byte-level XlsxSource / XlsxSink types and browser-safe helpers (fromBlob, fromResponse, fromStream, fromArrayBuffer, toBlob, toArrayBuffer).
  • Node fs glue (xlsx-kit/node) — fromFile, toFile, fromBuffer, toBuffer, fromReadable, toWritable.
  • Streaming (xlsx-kit/streaming) — loadWorkbookStream, createWriteOnlyWorkbook.
  • Workbook (xlsx-kit/workbook) — createWorkbook, addWorksheet, Workbook shape, defined names, calc properties, file metadata.
  • Worksheet (xlsx-kit/worksheet) — cells, rows, columns, merged cells, freeze panes, autoFilter, Tables, hyperlinks, data validations, conditional formatting, legacy comments.
  • Cell (xlsx-kit/cell) — Cell shape, formula helpers, inline rich-text composition.
  • Styles (xlsx-kit/styles) — Font, Fill, Border, Alignment, Protection, NumberFormat, full stylesheet pool with dedup, named styles + DXF.
  • Drawings (xlsx-kit/drawing) — anchors, images (PNG/JPEG/GIF/BMP/WebP/TIFF/SVG/EMF/WMF) with auto-detected format + dimensions.
  • Charts (xlsx-kit/chart) — 16 legacy c: chart kinds + 8 cx: chartex kinds (Sunburst, Treemap, Waterfall, Histogram, Pareto, Funnel, BoxWhisker, RegionMap).
  • Packaging / XML / ZIP / schema (xlsx-kit/packaging, xlsx-kit/xml, xlsx-kit/zip, xlsx-kit/schema) — the OPC layer below the workbook plus low-level XML reader / writer + Excel namespace constants. You won’t touch these directly unless you’re extending the library.

Cell helpers

FunctionPurpose
setCell(sheet, row, col, value)Set a cell value; coercion handled (string / number / boolean).
setFormula(cell, formula)Apply a formula to a Cell returned by setCell. Use setSharedFormula / setArrayFormula from xlsx-kit/cell for the array / shared variants.
getCell(sheet, row, col)Read a cell. Returns undefined if empty.
setCellStyle(wb, cell, opts)Apply per-aspect style (font / fill / border / alignment / numberFormat) to a cell.

Coordinates are 1-indexed (row=1, col=1 is A1). For A1 ↔ row/col conversion, reach for xlsx-kit/utils.

Loading and saving

// Source-side
loadWorkbook(source: XlsxSource): Promise<Workbook>
loadWorkbookStream(source: XlsxSource): Promise<StreamingWorkbook>

// Sink-side
workbookToBytes(wb: Workbook): Promise<Uint8Array>
saveWorkbook(wb: Workbook, sink: XlsxSink): Promise<void>
createWriteOnlyWorkbook(sink: XlsxSink): Promise<WriteOnlyWorkbook>

loadWorkbook / saveWorkbook / workbookToBytes come from xlsx-kit/io; loadWorkbookStream / createWriteOnlyWorkbook from xlsx-kit/streaming.

XlsxSource accepts anything from a Uint8Array to a ReadableStream<Uint8Array> to a Blob to a Node Readable. The matching from* helpers are split between xlsx-kit/node (fs / buffer / readable) and xlsx-kit/io (blob / response / web stream / array buffer).

Errors

  • Encrypted workbook — we detect the CFB Compound Document magic and throw EncryptedWorkbookError. Decrypt with msoffcrypto-tool first.
  • ZIP64 write — workbooks with > 65 535 entries get a ZIP64 EOCD record + locator. Read works too.
  • Malformed XML — every XML parse path runs through a single hardened SAX layer. Errors include the file part path so you know which xl/... part triggered it.

Migration

If you’re coming from openpyxl: see docs/migrate-from-openpyxl.md in the repo for the function-by-function map.