XLSX

Export

Export documents to buffer, blob, base64, or stream

The generateWorkbook() function generates a .xlsx file from options and returns the result in the requested format. Use generateWorkbookSync() for synchronous generation and generateWorkbookStream() for streaming.

generateWorkbook

Returns a Buffer (default in Node.js). Best for file I/O.

import { generateWorkbook } from "@office-open/xlsx";
import { writeFileSync } from "node:fs";

// Async (non-blocking)
const buffer = await generateWorkbook({
  /* options */
});
writeFileSync("output.xlsx", buffer);

Output Types

Control the output format with the second argument:

// Uint8Array (cross-platform)
const bytes = await generateWorkbook(opts, { type: "uint8array" });

// Blob (browser)
const blob = await generateWorkbook(opts, { type: "blob" });

// Base64 string (API payloads)
const base64 = await generateWorkbook(opts, { type: "base64" });

// ArrayBuffer
const ab = await generateWorkbook(opts, { type: "arraybuffer" });
typeReturnsUse Case
"nodebuffer"BufferNode.js file I/O
"uint8array"Uint8ArrayCross-platform raw bytes
"blob"BlobBrowser downloads
"base64"stringData URLs, API payloads
"arraybuffer"ArrayBufferMemory handling

Sync Variant

Use generateWorkbookSync() for synchronous generation — blocks the main thread but avoids async overhead:

import { generateWorkbookSync } from "@office-open/xlsx";

const buffer = generateWorkbookSync({
  /* options */
});

Streaming

Use generateWorkbookStream() for large documents — returns a ReadableStream without buffering the entire file:

import { generateWorkbookStream } from "@office-open/xlsx";
import { createWriteStream } from "node:fs";
import { Readable } from "node:stream";

const stream = generateWorkbookStream({
  /* options */
});
Readable.fromWeb(stream).pipe(createWriteStream("output.xlsx"));

Compression Options

All functions accept compression control. Default matches Microsoft Office: XML uses DEFLATE level 1 (SuperFast); media is split by type — already-compressed formats (PNG/JPEG/GIF) use STORE, the rest (EMF/WMF/BMP/TIFF/…) use DEFLATE level 6 / Normal.

// Default (MS Office)
await generateWorkbook(opts);

// Maximum XML compression
await generateWorkbook(opts, { compression: { xml: 9 } });

// No compression
await generateWorkbook(opts, { compression: { xml: 0 } });
OptionTypeDefaultDescription
compression.xmlnumber1DEFLATE level 0–9
compression.medianumber6compressible media only; PNG/JPEG/GIF always STORE

Browser Download Example

const blob = await generateWorkbook(opts, { type: "blob" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "output.xlsx";
a.click();
URL.revokeObjectURL(url);
Copyright © 2026