Excel files,
handled right.
Read, write, style and encrypt Excel .xlsx files in JavaScript and TypeScript, with a Rust core compiled to WebAssembly.
npm install modern-xlsx
Features
What the library reads and writes, all under the MIT license.
Cell styling
Fonts, fills, borders, alignment, text rotation, shrink-to-fit. Fluent builder API produces style indices for any cell.
Number formats
Built-in Excel format codes plus custom formats. formatCell() turns a value and a format code into display text for dates, currency, percentages and scientific notation.
Data validation
List, whole number, decimal, date, time, text length and custom formula rules, with input prompts and error messages.
Conditional formatting
Color scales, data bars, icon sets and formula-based rules, read and written.
Charts
Ten chart types (bar, column, line, pie, doughnut, scatter, area, radar, bubble and stock) built with the fluent ChartBuilder. Other chart XML is kept verbatim.
Images and barcodes
addImage embeds PNG, JPEG and GIF images; addBarcode draws QR, Code 128, EAN-13, UPC-A, Code 39, ITF-14 and GS1-128 symbols into the sheet.
Pivot tables
Read and write pivot tables. PivotTableBuilder builds the definition; Excel computes the table's values when it opens the file.
Formula engine
Evaluate formulas in memory with 54 built-in Excel functions, following Excel's semantics for type coercion, error propagation and operators.
Streaming writer
StreamingXlsxWriter writes rows one at a time without building a Workbook first. It holds the compressed output in memory until finish() returns it.
Frozen panes
Freeze rows, columns or both with frozenPane, or set split panes with splitPane.
Hyperlinks
Internal sheet links, external URLs and mailto links, with display text and tooltips.
Comments and notes
Add, read and remove cell comments with an author. Threaded comments are read and written too.
Sheet protection
Protect a worksheet through its sheetProtection settings, and lock the workbook structure or windows through Workbook.protection.
Encryption
Open and save password-protected .xlsx files (full build). Writes ECMA-376 Agile Encryption with AES-256, SHA-512 and 100,000 spin rounds; reads Agile and Standard Encryption.
Page setup
Paper size, orientation, print scale, margins, headers and footers, and page breaks.
Dates and Temporal
dateToSerial() takes a Date or a TemporalLike: a Temporal.PlainDate, a Temporal.PlainDateTime or any object with year, month and day. serialToDate() returns a Date.
Rust and WebAssembly core
The Rust core, compiled to WebAssembly, does the ZIP compression and decompression and the SAX-style XML parsing. The modern-xlsx/lite build leaves encryption out for a smaller binary.
Tree-shakable ESM
The modern-xlsx and modern-xlsx/lite entries are ES modules with "sideEffects": false and no runtime dependencies, so bundlers can drop unused JavaScript exports. The WASM binary is loaded whole.
Quick start
Create a styled spreadsheet, save it and read it back in Node.js.
import { initWasm, Workbook, readFile } from 'modern-xlsx'; await initWasm(); // Create a new workbook const wb = new Workbook(); const ws = wb.addSheet('Sales'); ws.cell('A1').value = 'Product'; ws.cell('B1').value = 'Revenue'; ws.cell('A2').value = 'Widget'; ws.cell('B2').value = 9999.99; // Style headers const header = wb.createStyle() .font({ bold: true, size: 14, color: '1F4E79' }) .fill({ pattern: 'solid', fgColor: 'D6E4F0' }) .alignment({ horizontal: 'center' }) .build(wb.styles); ws.cell('A1').styleIndex = header; ws.cell('B1').styleIndex = header; // Currency format const currency = wb.createStyle() .numberFormat('$#,##0.00') .build(wb.styles); ws.cell('B2').styleIndex = currency; await wb.toFile('sales.xlsx'); // Read the file back const saved = await readFile('sales.xlsx'); console.log(saved.getSheet('Sales')?.cell('A1').value); // 'Product'
API overview
Full documentation: the package README and the generated API reference.
| Category | Functions and classes |
|---|---|
| Core | initWasm() · Workbook · Worksheet · Cell |
| I/O | readFile() · readBuffer() · wb.toFile() · wb.toBuffer() · writeBlob() |
| Styles | StyleBuilder — .font() .fill() .border() .alignment() .numberFormat() .build() |
| Conversions | aoaToSheet() · jsonToSheet() · sheetToJson() · sheetToCsv() · sheetToHtml() |
| Dates | dateToSerial() · serialToDate() · isDateFormatId() |
| Formatting | formatCell() · getBuiltinFormat() |
| Cell references | encodeCellRef() · decodeCellRef() · encodeRange() · decodeRange() |
| Rich text | RichTextBuilder — .text() .bold() .italic() .styled() .build() |
Architecture
A TypeScript API over a Rust core compiled to WebAssembly.
Workbook data crosses the WASM boundary as JSON strings. The Rust core handles ZIP compression and decompression, SAX-style XML parsing and the shared string table (SST). On write it collects every shared-string cell into the SST first, then replaces each one's text with its SST index while it writes each sheet's XML, without cloning the worksheet. Inline-string cells stay inline.
Comparison
modern-xlsx next to SheetJS Community Edition 0.20.3 and SheetJS Pro. Competitor facts as of 2026-11-11, from docs.sheetjs.com, sheetjs.com/pro, the npm registry and the SheetJS CDN. The longer comparison is in FEATURE-COMPARISON.md.
| Feature | modern-xlsx | SheetJS CE | SheetJS Pro |
|---|---|---|---|
| Read and write .xlsx | Yes | Yes | Not stated |
| Cell styles on write | Yes | Partial: row and column styling metadata | Paid (Pro Basic) |
| Number formats rendered to text | Yes | Yes | Paid (SSF Pro, locale formats) |
| Conditional formatting on write | Yes | Paid (SheetJS Pro) | Paid (Pro Basic) |
| Data validation | Yes | Not documented | Paid (Pro Basic; read or write not stated) |
| Charts on write | Yes | Paid (Pro Chart) | Paid (Pro Chart) |
| Images on write | Yes | Paid (Pro Image) | Paid (Pro Image) |
| Pivot tables on write | Yes | Paid (add-on) | Paid (add-on) |
| Cell comments | Yes | Yes | Paid (comment rich text and styling) |
| Threaded comments | Yes | Yes | Not stated |
| Sheet protection on write | Yes | Yes | Not stated |
| Open password-encrypted files | Yes (Agile and Standard) | Partial: XOR-encrypted XLS only | Paid (encryption add-on) |
| Encrypt on write | Yes (Agile, AES-256) | Paid (Pro add-on) | Paid (encryption add-on) |
| Streaming write | Yes (StreamingXlsxWriter) | Partial: CSV, HTML, JSON and SpreadsheetML 2003 streams; no XLSX stream writer | Not stated |
| Browser, Node.js, Deno | Yes | Yes | Not stated |
| Bun | Yes | Partial: documented as experimental | Not stated |
| Cloudflare Workers | Yes | Not documented (a Deno Deploy demo exists) | Not stated |
| Bundled TypeScript types | Yes | Yes | Not stated |
| Current release on npm | Yes | No: npm stops at 0.18.5 (2022); 0.20.3 is on cdn.sheetjs.com | No: sold by inquiry |
| Runtime dependencies | 0 | 0 (0.20.3) | Not stated |
| License | MIT | Apache-2.0 | Commercial; price not published |
— in the SheetJS Pro column means sheetjs.com/pro does not state it (checked 2026-11-11).
modern-xlsx runtime rows: CI runs the tests on Node 24 and 26 and in Chromium, and runs the examples under Bun, Deno and a local Cloudflare Worker (wrangler dev --local). Encryption needs the full build, not modern-xlsx/lite.