-
Notifications
You must be signed in to change notification settings - Fork 1
API Reference
ABCrimson edited this page Mar 3, 2026
·
10 revisions
Initialize the WASM module. Must be called once before any other operation.
import { initWasm } from 'modern-xlsx';
await initWasm();Read an XLSX file from disk. Node.js / Bun / Deno only.
Read an XLSX file from a buffer. Works in all environments.
Write a workbook to a Blob for browser downloads.
const wb = new Workbook();| Property | Type | Description |
|---|---|---|
sheetNames |
string[] |
Names of all sheets |
sheetCount |
number |
Number of sheets |
dateSystem |
'date1900' | 'date1904' |
Date epoch system |
styles |
StylesData |
Styles collection |
namedRanges |
DefinedNameData[] |
Named ranges |
docProperties |
DocPropertiesData | null |
Document metadata |
workbookViews |
WorkbookViewData[] |
View settings |
| Method | Returns | Description |
|---|---|---|
addSheet(name) |
Worksheet |
Add a new sheet |
getSheet(name) |
Worksheet | undefined |
Get sheet by name |
getSheetByIndex(i) |
Worksheet | undefined |
Get sheet by index |
removeSheet(nameOrIndex) |
boolean |
Remove a sheet |
createStyle() |
StyleBuilder |
Create a style builder |
addNamedRange(name, value, sheetId?) |
void |
Add named range |
getNamedRange(name) |
DefinedNameData | undefined |
Get named range |
removeNamedRange(name) |
boolean |
Remove named range |
toBuffer() |
Promise<Uint8Array> |
Serialize to buffer |
toFile(path) |
Promise<void> |
Write to file |
toJSON() |
WorkbookData |
Get raw data |
| Property | Type | Description |
|---|---|---|
name |
string |
Sheet name (read/write) |
rows |
RowData[] |
All rows |
columns |
ColumnInfo[] |
Column definitions |
mergeCells |
string[] |
Merge ranges |
autoFilter |
AutoFilterData | null |
Auto filter config |
frozenPane |
FrozenPane | null |
Frozen pane config |
hyperlinks |
HyperlinkData[] |
Hyperlinks |
validations |
DataValidationData[] |
Validations |
comments |
CommentData[] |
Cell comments |
pageSetup |
PageSetupData | null |
Page setup |
pageMargins |
PageMarginsData | null |
Page margins |
sheetProtection |
SheetProtectionData | null |
Protection |
| Method | Returns | Description |
|---|---|---|
cell(ref) |
Cell |
Get or create a cell |
setColumnWidth(col, width) |
void |
Set column width |
setRowHeight(row, height) |
void |
Set row height |
setRowHidden(row, hidden) |
void |
Hide/show row |
addMergeCell(range) |
void |
Add merge |
removeMergeCell(range) |
boolean |
Remove merge |
addHyperlink(ref, location, opts?) |
void |
Add link |
removeHyperlink(ref) |
boolean |
Remove link |
addValidation(ref, rule) |
void |
Add validation |
removeValidation(ref) |
boolean |
Remove validation |
addComment(ref, author, text) |
void |
Add comment |
removeComment(ref) |
boolean |
Remove comment |
| Property | Type | Description |
|---|---|---|
reference |
string |
Cell reference (e.g. "A1") |
type |
CellType |
Value type |
value |
string | number | boolean | null |
Cell value (read/write) |
formula |
string | null |
Formula (read/write) |
styleIndex |
number | null |
Style index (read/write) |
Fluent builder for creating cell styles:
const idx = wb.createStyle()
.font({ name: 'Arial', size: 12, bold: true, color: 'FF0000' })
.fill({ pattern: 'solid', fgColor: 'FFFF00' })
.border({ top: { style: 'thin', color: '000000' } })
.alignment({ horizontal: 'center', wrapText: true })
.protection({ locked: true })
.numberFormat('#,##0.00')
.build(wb.styles);| Function | Description |
|---|---|
aoaToSheet(data, opts?) |
Array-of-arrays to Worksheet |
jsonToSheet(data, opts?) |
JSON array to Worksheet |
sheetToJson(ws, opts?) |
Worksheet to JSON array |
sheetToCsv(ws, opts?) |
Worksheet to CSV string |
sheetToHtml(ws, opts?) |
Worksheet to HTML table |
sheetAddAoa(ws, data, opts?) |
Append array data |
sheetAddJson(ws, data, opts?) |
Append JSON data |
| Function | Description |
|---|---|
dateToSerial(date) |
Date/Temporal to Excel serial |
serialToDate(serial) |
Excel serial to Date |
isDateFormatId(id) |
Check if built-in date format |
isDateFormatCode(code) |
Check if date format string |
| Function | Description |
|---|---|
encodeCellRef(row, col) |
(0, 0) → "A1"
|
decodeCellRef(ref) |
"A1" → { row: 0, col: 0 }
|
encodeRange(start, end) |
Addresses to range string |
decodeRange(range) |
Range string to addresses |
columnToLetter(col) |
0 → "A"
|
letterToColumn(letter) |
"A" → 0
|
| Function | Description |
|---|---|
formatCell(value, format) |
Format value with Excel format code |
getBuiltinFormat(id) |
Get built-in format string by ID |
| Function | Description |
|---|---|
encodeCode39(data) |
Code 39 barcode matrix |
encodeCode128(data) |
Code 128 barcode matrix |
encodeEAN13(data) |
EAN-13 barcode matrix |
encodeUPCA(data) |
UPC-A barcode matrix |
encodeITF14(data) |
ITF-14 barcode matrix |
encodeGS1128(data) |
GS1-128 barcode matrix |
encodeQR(data) |
QR Code matrix |
encodeDataMatrix(data) |
Data Matrix barcode matrix |
encodePDF417(data) |
PDF417 barcode matrix |
| Function | Description |
|---|---|
renderBarcodePNG(matrix, opts?) |
Render barcode matrix to PNG Uint8Array
|
Options: { scale?: number, margin?: number }
| Function | Description |
|---|---|
generateBarcode(wb, ws, opts) |
One-call barcode generation + XLSX embedding |
generateDrawingXml(anchors) |
Generate drawing XML for image anchors |
generateDrawingRels(rels) |
Generate drawing relationships XML |
DrawBarcodeOptions:
{
type: BarcodeType; // 'code39' | 'code128' | 'ean13' | 'upca' | 'itf14' | 'gs1128' | 'qr' | 'datamatrix' | 'pdf417'
data: string;
anchor: ImageAnchor;
scale?: number;
margin?: number;
}| Type | Description |
|---|---|
BarcodeMatrix |
{ rows: number[][]; width: number; height: number } |
BarcodeType |
Union of supported barcode format strings |
DrawBarcodeOptions |
Options for generateBarcode()
|
ImageAnchor |
{ from: { col, row }, to: { col, row } } |
RenderOptions |
{ scale?: number; margin?: number } |
modern-xlsx v1.0.0
Getting Started
Guides
- Charts & Visualizations
- Formula Engine
- Table Layout Engine
- Tables & Print Layout
- Encryption
- Feature Comparison
Reference
Migration
Project