Skip to content

Migration from SheetJS

ABCrimson edited this page Mar 2, 2026 · 2 revisions

Migration from SheetJS

This guide maps common SheetJS (xlsx/XLSX) API calls to their modern-xlsx equivalents.

Initialization

// SheetJS — no init needed
import * as XLSX from 'xlsx';

// modern-xlsx — init WASM once
import { initWasm } from 'modern-xlsx';
await initWasm();

Reading Files

// SheetJS
const wb = XLSX.readFile('data.xlsx');
const wb = XLSX.read(buffer, { type: 'buffer' });

// modern-xlsx
import { readFile, readBuffer } from 'modern-xlsx';
const wb = await readFile('data.xlsx');
const wb = await readBuffer(uint8Array);

Writing Files

// SheetJS
XLSX.writeFile(wb, 'output.xlsx');
const buf = XLSX.write(wb, { type: 'buffer', bookType: 'xlsx' });

// modern-xlsx
await wb.toFile('output.xlsx');
const buf = await wb.toBuffer();

Sheet Access

// SheetJS
const ws = wb.Sheets['Sheet1'];
const names = wb.SheetNames;

// modern-xlsx
const ws = wb.getSheet('Sheet1');
const names = wb.sheetNames;

Cell Access

// SheetJS
const cell = ws['A1'];
const value = cell?.v;

// modern-xlsx
const cell = ws.cell('A1');
const value = cell.value;

Array of Arrays

// SheetJS
const ws = XLSX.utils.aoa_to_sheet(data);
const aoa = XLSX.utils.sheet_to_json(ws, { header: 1 });

// modern-xlsx
import { aoaToSheet, sheetToJson } from 'modern-xlsx';
const ws = aoaToSheet(data);
const json = sheetToJson(ws);

JSON Conversion

// SheetJS
const data = XLSX.utils.sheet_to_json(ws);
const csv = XLSX.utils.sheet_to_csv(ws);

// modern-xlsx
import { sheetToJson, sheetToCsv } from 'modern-xlsx';
const data = sheetToJson(ws);
const csv = sheetToCsv(ws);

Styling (SheetJS Pro → modern-xlsx Free)

// SheetJS Pro (paid)
ws['A1'].s = {
  font: { bold: true, color: { rgb: 'FF0000' } },
  fill: { fgColor: { rgb: 'FFFF00' } },
};

// modern-xlsx (free)
const style = wb.createStyle()
  .font({ bold: true, color: 'FF0000' })
  .fill({ pattern: 'solid', fgColor: 'FFFF00' })
  .build(wb.styles);
ws.cell('A1').styleIndex = style;

Key Differences

Aspect SheetJS modern-xlsx
Module format CJS + global ESM only
Types @types/xlsx (partial) Built-in, strict
Styling Pro only (paid) Free
Cell access ws['A1'] ws.cell('A1')
I/O Synchronous Async (WASM)
Date handling dateNF option dateToSerial() + format
npm availability CDN only npm registry
Bundle format Single large file Tree-shakable ESM

Clone this wiki locally