Top-level API
Load the package as const XLSX = require("@agent-sheet/wasm"). In an ES module,
use import XLSX from "@agent-sheet/wasm". Node does not support named imports from
this CommonJS package.
The spreadsheet engine is a WebAssembly module embedded in the JavaScript files.
Parsing and serialization are synchronous. writeFileAsync is the exception for
file I/O: it serializes synchronously, then writes the file asynchronously.
| Signature | Parameters and behavior | Returns |
|---|---|---|
read(data, options?) |
Parse text, binary strings, base64, Buffer, Uint8Array, ArrayBuffer or byte arrays. options.type selects the representation. Detects the spreadsheet format from content. |
A workbook |
readFile(filename, options?) |
Read a file from disk and parse it. Node only. filename is a path. |
A workbook |
readFileSync(filename, options?) |
Alias of readFile. |
A workbook |
options is a ParsingOptions object. The result
normally has SheetNames (names in display order) and Sheets (worksheets keyed
by name). Metadata-only read options may omit worksheet data.
const XLSX = require("@agent-sheet/wasm");const assert = require("node:assert/strict");const workbook = XLSX.read("Product,Quantity\nPens,12", { type: "string" });assert.deepEqual(workbook.SheetNames, ["Sheet1"]);assert.equal(workbook.Sheets.Sheet1.B2.v, 12);See Reading files for partial reads and dense worksheets.
Serialize in memory
Section titled “Serialize in memory”| Signature | Parameters and behavior | Returns |
|---|---|---|
write(workbook, options) |
Serialize a workbook. bookType chooses the format; type chooses the representation. |
Data in the requested representation |
writeXLSX(workbook, options) |
XLSX-specific serialization. Use for XLSX output. | Data in the requested representation |
Use type: "buffer" for a Node Buffer, "array" for a Uint8Array,
"base64" for base64 text, or "binary" for a binary string. "string"
is for text formats such as CSV, not XLSX. See WritingOptions.
const XLSX = require("@agent-sheet/wasm");const assert = require("node:assert/strict");const workbook = XLSX.utils.book_new();XLSX.utils.book_append_sheet(workbook, XLSX.utils.aoa_to_sheet([["Total", 42]]), "Summary");const bytes = XLSX.write(workbook, { type: "buffer", bookType: "xlsx" });assert.ok(Buffer.isBuffer(bytes));assert.equal(XLSX.read(bytes).Sheets.Summary.B1.v, 42);Write files
Section titled “Write files”| Signature | Parameters and behavior | Returns |
|---|---|---|
writeFile(workbook, filename, options?) |
Save to disk in Node; start a download in browsers. If bookType is absent, infer the format from the filename. |
No result to consume |
writeFileSync(workbook, filename, options?) |
Alias of writeFile; it does not add browser filesystem access. |
No result to consume |
writeFileXLSX(workbook, filename, options?) |
XLSX-specific file output. | No result to consume |
writeFileAsync(filename, workbook, options?, callback) |
Node file output with callback completion. Notice that the filename comes first. Serialization is synchronous; file I/O is asynchronous. | No result to consume; use the callback |
The callback follows Node’s file-write convention: check the error argument.
Serialization errors can be thrown before the callback is scheduled. This
function does not return a Promise. With no options, use
writeFileAsync(filename, workbook, callback).
const XLSX = require("@agent-sheet/wasm");const assert = require("node:assert/strict");const workbook = XLSX.utils.book_new();XLSX.utils.book_append_sheet(workbook, XLSX.utils.aoa_to_sheet([[7]]), "Data");XLSX.writeFileAsync("async.xlsx", workbook, { bookType: "xlsx" }, (error) => { if (error) throw error; assert.equal(XLSX.readFile("async.xlsx").Sheets.Data.A1.v, 7);});See Writing files for format selection and metadata limits.
Configuration
Section titled “Configuration”| Signature or property | Meaning | Returns |
|---|---|---|
version |
Compatibility API version (2.20260615.1), independent of the npm release version. |
A string |
set_fs(fs) |
Register a Node-compatible filesystem module for file helpers. Useful when a bundler does not provide it automatically. | No result to consume |
set_cptable(table) |
Register codepage tables, such as the package’s dist/cpexcel.js export. |
No result to consume |
set_date_style(format) |
Compatibility helper that changes built-in date format 14. Prefer explicit formats or SSF locale configuration for new code. |
No result to consume |
cycle_width(width) |
Round a width to a value representable by spreadsheet file formats. Input is in spreadsheet width units, not pixels. | A number |
These settings apply to the library instance in the current JavaScript realm.
A worker has its own instance. Register locale settings before a read if you
want generated cell text (w) to use them.
Lower-level parsers
Section titled “Lower-level parsers”Prefer read unless you already have a container from another API.
| Signature | Parameters | Returns |
|---|---|---|
parse_xlscfb(container, options?) |
A CFB container holding a BIFF workbook, plus parsing options. Not present in the mini distribution. | A workbook |
parse_zip(zip, options?) |
An already extracted ZIP object in the shape expected by the library, plus parsing options. It is not an API for arbitrary ZIP libraries’ objects. | A workbook |
Namespaces
Section titled “Namespaces”- utils: worksheet creation, conversion, addresses, styles and cells.
- Template helpers: edits to an existing XLSX/XLSM package.
- SSF: number and date formatting.
- CFB: compound-file containers.
- stream: Node readable output streams.
Encryption and compatibility
Section titled “Encryption and compatibility”File encryption is not available. utils.hash_password and
utils.test_password appear in the declarations for compatibility with the
original @sheet/edit package, but are absent at runtime. Worksheet protection
is a different feature; see Protection.