XLSX

@office-open/xlsx

Generate .xlsx spreadsheets with a declarative TypeScript API

Installation

pnpm add @office-open/xlsx

Quick Start

{
  "worksheets": [
    {
      "name": "Sheet1",
      "children": [
        { "cells": [{ "value": "Name" }, { "value": "Score" }] },
        { "cells": [{ "value": "Alice" }, { "value": 95 }] },
        { "cells": [{ "value": "Bob" }, { "value": 88 }] }
      ]
    }
  ]
}

Main Components

ComponentDescription
WorkbookRoot workbook container with worksheets and properties
WorksheetIndividual sheet with cells, styles, and features
CellCell with value, style, and formatting
RowRow container with height and visibility
ColumnColumn definition with width and range
StylesIndex-based style system (fonts, fills, borders)
SharedStringsShared string table for string deduplication

Patching

Modify existing .xlsx templates by replacing {{placeholder}} tokens with new content:

import { patchWorkbook } from "@office-open/xlsx";

const result = await patchWorkbook({
  outputType: "nodebuffer",
  data: templateBuffer,
  patches: {
    name: { value: "John Doe" },
    amount: { value: 1500 },
    date: { value: "2024-12-31" },
  },
});

See Patching for full documentation.

Parsing

Parse existing .xlsx files into WorkbookOptions for inspection or round-trip workflows:

import { parseWorkbook } from "@office-open/xlsx";

const opts = parseWorkbook(buffer);
// opts.worksheets — worksheet array
// opts.worksheets[0].children — rows with cells
// opts.title, opts.creator — core properties

See Parsing for full documentation.

Export Formats

Every async method has a synchronous counterpart (e.g., toBufferSync). See the Export page for the full list.

MethodReturnsUse Case
Packer.toBuffer(wb)BufferNode.js file I/O
Packer.toBlob(wb)BlobBrowser downloads
Packer.toBase64String(wb)stringData URLs, API payloads
Packer.toString(wb)stringDebugging, inspection
Packer.toStream(wb)ReadableStream<Uint8Array>Streaming large files
Copyright © 2026