XLSX

@office-open/xlsx

Generate, parse, and patch .xlsx spreadsheets with a declarative TypeScript API

Installation

pnpm add @office-open/xlsx

Quick Start

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

Main Components

ComponentDescription
worksheets arrayRoot workbook options with worksheets and properties
worksheetIndividual sheet with rows, styles, and features
rows, cells, columnsRows, cells, and columns with value, style, height, and width
stylesIndex-based style system (fonts, fills, borders)
sharedStringsShared string table for string deduplication
tableData tables with filtering, sorting, and totals
pivotTableData pivot tables with aggregation and filtering
drawingImages and charts anchored to cells
commentsCell comments with author tracking and rich text
hyperlinkExternal and internal hyperlinks
mergeCellsMerge cell ranges across rows and columns
dataValidationList, number, date, and custom validation rules
conditionalFormattingCell value-based formatting rules
autoFilterColumn header filter dropdowns
freezePaneFreeze rows and columns for scrollable headers
sheetProtectionPassword-protect worksheets and editable ranges
revisionLogTrack changes with revision logs
pageSetupPage size, margins, orientation, and print settings
headerFooterPrint headers and footers

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,
  placeholders: {
    name: "John Doe",
    amount: 1500,
    date: new Date("2024-12-31"),
  },
});

See 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].rows — rows with cells
// opts.title, opts.creator — core properties

See for full documentation.

Export Formats

Every async function has a synchronous counterpart (e.g., generateWorkbookSync). See the page for the full list.

FunctionReturnsUse Case
generateWorkbook(opts)BufferNode.js file I/O
generateWorkbook(opts, { type: "blob" })BlobBrowser downloads
generateWorkbook(opts, { type: "base64" })stringData URLs, API payloads
generateWorkbook(opts, { type: "string" })stringDebugging, inspection
generateWorkbookStream(opts)ReadableStream<Uint8Array>Streaming large files
Copyright © 2026