Skip to content

sebastian-software/xlsx-format

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

xlsx-format

Powered by Sebastian Software npm version CI codecov license node bun browser TypeScript

The XLSX library your bundler will thank you for. Zero dependencies. Fully async. Works in Node.js and the browser. Use it for simple data conversion, or replace ExcelJS for styled browser report exports without carrying a workbook framework just for formatting.

Documentation | API Reference

npm install xlsx-format
import { readFile, writeFile } from "node:fs/promises";
import { read, write, sheetToJson, jsonToSheet, createWorkbook } from "xlsx-format";

// Read an Excel file into JSON
const workbook = await read(await readFile("report.xlsx"));
const rows = sheetToJson(workbook.Sheets[workbook.SheetNames[0]]);

// Write JSON back to Excel
const sheet = jsonToSheet([
	{ Name: "Alice", Revenue: 48000 },
	{ Name: "Bob", Revenue: 52000 },
]);
await writeFile("output.xlsx", await write(createWorkbook(sheet, "Q4 Sales")));

Why xlsx-format?

Most projects just need XLSX -- but the popular libraries ship with support for dozens of legacy formats, pull in 7-9 runtime dependencies, and lock you into synchronous APIs that block the event loop.

xlsx-format does one thing well: read and write modern Excel files. The result is a library you can actually tree-shake, await, and ship to the browser without a separate bundle.

xlsx-format SheetJS (xlsx) ExcelJS
Written in TypeScript (strict) JavaScript (with .d.ts) TypeScript
Async Yes (streaming ZIP) No Partial
Module format ESM + CJS CJS only CJS only
Tree-shakeable Yes No Partial
Runtime deps 0 7 9
Browser support Yes (read / write) Yes (separate bundle) No
Formats XLSX / XLSM / CSV / TSV / HTML 30+ formats XLSX / CSV
Styled reports Yes Yes Yes
API style Named exports, async Namespace object Class-based
Test coverage 91% (Codecov) Not measured Not measured
License Apache 2.0 Apache 2.0 MIT

For a detailed feature matrix (cell data, formulas, styles, comments, hyperlinks, and more), see Why xlsx-format? in the docs.

Runs everywhere

xlsx-format is fully platform-agnostic -- it never imports node:fs or any other Node.js built-in. This means it works out of the box in browsers, edge runtimes (Cloudflare Workers, Deno Deploy), and Node.js without bundler polyfills.

Node.js -- Pair read() / write() with Node's fs module:

import { readFile, writeFile } from "node:fs/promises";
import { read, write } from "xlsx-format";

const wb = await read(await readFile("input.xlsx"));
await writeFile("output.xlsx", await write(wb));

Browsers -- Use the File API or fetch:

import { read, write } from "xlsx-format";

// Read from a file input
const wb = await read(await file.arrayBuffer());

// Trigger a download
const blob = new Blob([await write(wb, { type: "array" })], {
	type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
});
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "output.xlsx";
link.click();

Styled report exports

Need polished XLSX output, but not the full ExcelJS object model? xlsx-format can write styled workbook reports with fonts, fills, borders, number formats, row heights, column widths, merged title rows, and frozen panes. Styling is opt-in with cellStyles: true, so existing unstyled exports keep their lean output.

import {
	arrayToSheet,
	createWorkbook,
	freezePanes,
	mergeCells,
	setCellStyle,
	setColumnWidth,
	setRowHeight,
	styleRange,
	write,
	type CellStyle,
} from "xlsx-format";

const titleStyle: CellStyle = {
	font: { name: "Calibri", size: 14, bold: true, color: { argb: "FFFFFFFF" } },
	fill: { patternType: "solid", fgColor: { argb: "FF1F4E79" } },
	alignment: { vertical: "middle" },
};

const headerStyle: CellStyle = {
	font: { bold: true, color: { argb: "FFFFFFFF" } },
	fill: { patternType: "solid", fgColor: { argb: "FF2E75B6" } },
	alignment: { horizontal: "center", vertical: "middle", wrapText: true },
};

const ws = arrayToSheet([
	["Northstar Solar PPA - Q2 Report", null, null],
	["Month", "Expected MWh", "Settlement"],
	["Apr 2026", 12400, -18350],
]);

setCellStyle(ws["A1"], titleStyle);
styleRange(ws, "A2:C2", headerStyle);
mergeCells(ws, "A1:C1");
setRowHeight(ws, 0, 30);
setColumnWidth(ws, 0, 18);
freezePanes(ws, { ySplit: 2 });

const bytes = await write(createWorkbook(ws, "Overview"), {
	type: "array",
	cellStyles: true,
});

See the Styled Workbooks guide for a full report export example.

Switching from SheetJS

The API is intentionally close to SheetJS. Three things change:

  1. read() and write() are async (ZIP uses streaming)
  2. Named imports replace the namespace: import { read } from "xlsx-format"
  3. Utility names are camelCase: sheetToJson instead of XLSX.utils.sheet_to_json
- import XLSX from "xlsx";
+ import { read, write, sheetToJson, sheetToCsv } from "xlsx-format";

- const wb = XLSX.read(buffer);
+ const wb = await read(buffer);

- const rows = XLSX.utils.sheet_to_json(ws);
+ const rows = sheetToJson(ws);

- const buf = XLSX.write(wb, { type: "buffer", bookType: "xlsx" });
+ const buf = await write(wb, { type: "buffer" });

Cell objects keep the same shape: { t: "n", v: 42, w: "42" } works exactly as before. For a full function mapping table, see the Migration Guide.

Acknowledgments

Based on the work of SheetJS, originally created by SheetJS LLC. Thank you to the SheetJS team and its contributors for building the foundation this library stands on.

License

Apache 2.0 -- see LICENSE for details.

Copyright (C) 2012-present SheetJS LLC (original work)


Sebastian Software

Open Source at Sebastian Software
Copyright © 2025–2026 Sebastian Software GmbH

About

Modern XLSX reader/writer for TypeScript, Node.js, and browsers. Zero dependencies, async APIs, styled report exports.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors