XLSX

Parsing

Parse, inspect, and round-trip .xlsx files

The library provides two levels of parsing API:

  • parseWorkbook — High-level round-trip API that returns WorkbookOptions
  • parseXlsx — Low-level access to the raw XML parts of a .xlsx file

Both functions accept any DataType input: Uint8Array, ArrayBuffer, DataView, number[], base64 string, and more.

Round-Trip (parseWorkbook)

The parseWorkbook function parses a .xlsx file into the same WorkbookOptions format used by the Workbook constructor, enabling full round-trip (export → parse → re-export):

import { Workbook, Packer, parseWorkbook } from "@office-open/xlsx";
import { readFileSync } from "node:fs";

// Parse an existing .xlsx file
const opts = parseWorkbook(readFileSync("input.xlsx"));

// Modify cells if needed, then re-export
const wb = new Workbook(opts);
const buffer = await Packer.toBuffer(wb);

The returned options contain the same structure as the input format:

{
  "title": "My Workbook",
  "creator": "Author",
  "worksheets": [
    {
      "name": "Sheet1",
      "children": [
        { "cells": [{ "value": "Name" }, { "value": "Score" }] },
        { "cells": [{ "value": "Alice" }, { "value": 95 }] }
      ],
      "columns": [{ "min": 1, "max": 1, "width": 15 }],
      "mergeCells": [{ "from": { "row": 1, "col": 1 }, "to": { "row": 1, "col": 2 } }],
      "freezePanes": { "row": 1 },
      "autoFilter": "A1:B2"
    }
  ]
}

Parsed Fields

FieldSourceDescription
worksheetsxl/worksheets/sheet{n}Worksheet array with children and options
titledocProps/core.xmlWorkbook title
creatordocProps/core.xmlAuthor name
subjectdocProps/core.xmlSubject
keywordsdocProps/core.xmlKeywords
descriptiondocProps/core.xmlDescription
lastModifiedBydocProps/core.xmlLast modified by
revisiondocProps/core.xmlRevision number

Worksheet Parsed Fields

FieldDescription
nameWorksheet name
childrenArray of rows, each with cells
columnsColumn definitions with width
mergeCellsMerged cell ranges
freezePanesFreeze pane configuration
autoFilterAuto-filter range string
dataValidationsData validation rules
conditionalFormatsConditional formatting rules

Low-Level Parsing (parseXlsx)

The parseXlsx function reads a .xlsx file and provides access to its raw XML parts:

import { parseXlsx } from "@office-open/xlsx";
import { readFileSync } from "node:fs";

const doc = parseXlsx(readFileSync("input.xlsx"));

// Access workbook element
console.log(doc.workbook);

// Access worksheet paths
console.log(doc.worksheets);

// Access styles element
console.log(doc.styles);

// Access shared strings element
console.log(doc.sharedStrings);

XlsxDocument API

The returned XlsxDocument object contains:

PropertyTypeDescription
docParsedArchiveFull parsed archive (all parts)
workbookElement | undefinedWorkbook element (xl/workbook.xml)
worksheetsstring[]Worksheet paths
stylesElement | undefinedStyles element
sharedStringsElement | undefinedShared strings element
partRefsXlsxPartRefsReferences to charts, media, drawings
corePropsstring | undefinedPath to core properties
appPropsstring | undefinedPath to app properties

Accessing Parts

const doc = parseXlsx(data);

// Get all parts by path
const workbook = doc.doc.get("xl/workbook.xml");
const styles = doc.doc.get("xl/styles.xml");
const sheet1 = doc.doc.get("xl/worksheets/sheet1.xml");

// Part references map to paths
for (const path of doc.partRefs.worksheets) {
  const sheet = doc.doc.get(path);
}

Working with XML Elements

The parsed elements use the @office-open/xml library's Element type:

import { attr } from "@office-open/xml";

// Access element attributes
for (const child of doc.workbook?.elements ?? []) {
  console.log(child.name);
}

Use Cases

  • Round-trip — Parse a .xlsx, modify cells, and re-export
  • Extract data — Walk the worksheet rows to extract cell values
  • Merge workbooks — Parse multiple .xlsx files and combine their sheets
  • Inspect formatting — Read style definitions and number formats
  • Transform — Modify parsed elements and rebuild a workbook
Copyright © 2026