Skip to content

Migration from ExcelJS

ABCrimson edited this page Mar 3, 2026 · 3 revisions

Migration from ExcelJS

This guide maps common ExcelJS API calls to their modern-xlsx equivalents.

Installation

- npm install exceljs
+ npm install modern-xlsx

Initialization

// ExcelJS — no init needed
import ExcelJS from 'exceljs';

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

Creating a Workbook

// ExcelJS
const wb = new ExcelJS.Workbook();

// modern-xlsx
const wb = new Workbook();

Adding Sheets

// ExcelJS
const ws = wb.addWorksheet('Sales');

// modern-xlsx
const ws = wb.addSheet('Sales');

Cell Values

// ExcelJS
ws.getCell('A1').value = 'Hello';
ws.getCell('A2').value = 42;

// modern-xlsx
ws.cell('A1').value = 'Hello';
ws.cell('A2').value = 42;

Formulas

// ExcelJS
ws.getCell('A4').value = { formula: 'SUM(A1:A3)', result: 42 };

// modern-xlsx
ws.cell('A4').formula = 'SUM(A1:A3)';

Styling

// ExcelJS — per-cell style objects
ws.getCell('A1').font = { bold: true, color: { argb: 'FFFF0000' } };
ws.getCell('A1').fill = {
  type: 'pattern',
  pattern: 'solid',
  fgColor: { argb: 'FFFFFF00' },
};

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

Merge Cells

// ExcelJS
ws.mergeCells('A1:C1');

// modern-xlsx
ws.addMergeCell('A1:C1');

Column Widths & Row Heights

// ExcelJS
ws.getColumn('A').width = 20;
ws.getRow(1).height = 30;

// modern-xlsx
ws.setColumnWidth(1, 20);
ws.setRowHeight(1, 30);

Frozen Panes

// ExcelJS
ws.views = [{ state: 'frozen', xSplit: 0, ySplit: 1 }];

// modern-xlsx
ws.frozenPane = { rows: 1, cols: 0 };

Data Validation

// ExcelJS
ws.getCell('A1').dataValidation = {
  type: 'list',
  formulae: ['"Yes,No,Maybe"'],
};

// modern-xlsx
ws.addValidation('A1', {
  validationType: 'list',
  formula1: '"Yes,No,Maybe"',
  showDropDown: true,
});

Reading Files

// ExcelJS
const wb = new ExcelJS.Workbook();
await wb.xlsx.readFile('data.xlsx');
await wb.xlsx.load(buffer);

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

Writing Files

// ExcelJS
await wb.xlsx.writeFile('output.xlsx');
const buffer = await wb.xlsx.writeBuffer();

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

Key Differences

Feature ExcelJS modern-xlsx
Runtime Pure JS (streaming) Rust WASM
Styles Per-cell objects Shared style table + index
Cell access ws.getCell('A1') ws.cell('A1')
Merge cells ws.mergeCells(range) ws.addMergeCell(range)
Sheet creation wb.addWorksheet(name) wb.addSheet(name)
Dependencies 14+ 0 (WASM bundled)
Bundle size ~2 MB ~994 KB

Clone this wiki locally