npm.io
0.3.0 • Published 23h ago

openjsxl

Licence
MIT
Version
0.3.0
Deps
1
Size
4 kB
Vulns
0
Weekly
0
Stars
1

openjsxl

npm version install size types included license: MIT

Fast, zero-dependency, TypeScript-first Excel (.xlsx) reader and writer for JavaScript runtimes — Node, Deno, Bun, the browser, and edge. This is the package to install; it re-exports the @openjsxl/core engine.

npm install openjsxl
import { openXlsx } from 'openjsxl'
import { readFile } from 'node:fs/promises'

const wb = await openXlsx(await readFile('data.xlsx'))

// Typed cells: narrowing on `cell.type` gives a correctly typed `cell.value`.
const a1 = wb.sheet('Sheet1').cell('A1')
console.log(a1.type, a1.value) // e.g. "string" "hello"

// Stream a whole sheet, row at a time.
for await (const row of wb.sheet(wb.sheets[0].name).rows()) {
	console.log(row.index, row.cells.map((c) => c.value))
}

For very large sheets use streamSheetRows (constant memory); a worksheet also exposes numberFormat, dimension, mergedCells, hyperlinks, comments, and visible, and the reader throws a typed XlsxError (with a discriminating code) on malformed input.

Writing (0.3): describe a workbook as plain data and get back .xlsx bytes — cell types are inferred from the JS values:

import { writeXlsx } from 'openjsxl'

const bytes = await writeXlsx({
	sheets: [{ name: 'Report', rows: [['Item', 'Added'], ['Apples', new Date('2024-01-15')]] }],
})

workbookToInput turns an open Workbook back into writer input for read → modify → write.

See the project README for the full guide, design notes, and roadmap.

License

MIT