Skip to content

Writing options

Pass these options to write, writeXLSX, writeFile, writeFileXLSX, or writeFileAsync. The file helpers can infer a format from the filename; in-memory serialization has no filename, so choose bookType explicitly for clarity.

Option Type / default Effect
type string Select the representation returned by write
bookType format identifier; "xlsx" Select the output format. writeFile can infer it from the filename
sheet string or zero-based number Choose a sheet for single-sheet formats; default is the first sheet
type Result
"buffer" Node Buffer
"array" Uint8Array
"base64" Base64 text
"binary" Binary string with one character per byte
"string" Plain text; only for text formats
"file" File-oriented mode; use writeFile instead

See Supported formats for bookType values. The output type and file format are separate choices: XLSX can be returned as base64, for example, but it cannot be returned as plain text.

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([["Label", "Amount"], ["Fees", 25]]), "Costs");
const base64 = XLSX.write(workbook, { type: "base64", bookType: "xlsx" });
assert.equal(XLSX.read(base64, { type: "base64" }).Sheets.Costs.B2.v, 25);
const csv = XLSX.write(workbook, { type: "string", bookType: "csv", FS: ";" });
assert.ok(csv.includes("Label;Amount"));
Option Type Effect
compression boolean Deflate ZIP entries for XLSX, XLSM, XLSB and ODS
bookSST boolean Emit a shared string table; needed for rich text in XLS/XLSB
themeXLSX string Supply replacement theme XML for XLSX/XLSM/XLSB
codepage number Choose a legacy text encoding where the format supports it
numbers string Supply the Numbers payload from dist/xlsx.zahl.js; required for bookType: "numbers"

Compression changes storage size, not the workbook’s cell values. A shared string table can change size and write time; it is not required for ordinary XLSX text cells.

Option Type / default Effect
cellStyles boolean Write styles and supported presentation metadata
cellDates boolean Write native date cells in XLSX/XLSM
ignoreEC boolean; true Suppress spreadsheet warnings about numbers stored as text
Props properties object Write these document properties instead of wb.Props
bookVBA boolean Re-emit wb.vbaraw in a macro-capable format such as XLSM
bookImages boolean Request image output where supported
sheetStubs boolean Shared compatibility option for blank stub cells

Properties include Title, Subject, Author, Manager, Company, Category, Keywords, Comments, LastAuthor, and CreatedDate.

const XLSX = require("@agent-sheet/wasm");
const assert = require("node:assert/strict");
const workbook = XLSX.utils.book_new();
const sheet = XLSX.utils.aoa_to_sheet([["Invoice"]]);
sheet.A1.s = { bold: true };
XLSX.utils.book_append_sheet(workbook, sheet, "Cover");
const bytes = XLSX.write(workbook, {
type: "buffer", bookType: "xlsx", cellStyles: true,
Props: { Title: "June invoice", Author: "Billing" }
});
const result = XLSX.read(bytes, { cellStyles: true });
assert.equal(result.Props.Title, "June invoice");
assert.ok(result.Sheets.Cover.A1.s.bold);

A write option does not guarantee that every metadata feature round-trips in every format. See Print settings and Pivot tables for their APIs. For existing workbooks, template mode preserves package features outside the ordinary workbook model.

Option Type Effect
FS string Field separator for CSV/text
RS string Record separator for CSV/text

For additional sheet-conversion controls such as forceQuotes, skipHidden, strip, or blankrows, use utils.sheet_to_csv and its options. See Converting sheets.

Set template: true to write using the original package retained by a template: true read. This is for XLSX/XLSM. Do not pass it to a newly constructed workbook and expect an original package to exist.

Use template helpers to record edits. Direct changes to arbitrary wb.Sheets fields are not a substitute for the helpers. Untouched package parts remain preserved.

Option Behavior
WTF Request errors for malformed or unsupported content
password Accepted in the declarations; encrypted output is not available
PPI Screen density for converting wpx/hpx sizes: 72, 96 (default), 120, 144, "osx" or "win"

Protection flags and worksheet passwords are not file encryption. See Protection.