📗
Excel-Builder-Vanilla
Live DemoGitHub
  • Introduction
  • Cookbook
    • Creating Workbooks
    • Creating Worksheets
    • Adding data to a Worksheet
    • Sizing/Hiding Columns
    • Setting row height/style
    • Fonts and Colors
    • Formatting numbers, dates, etc
    • Alignment
    • Background Fillers
    • Formulas
    • Tables
    • Theming Tables
    • Tables Summaries
    • Adding Headers and Footers to a Worksheet
    • Inserting images into spreadsheets
    • Streaming Export API
Powered by GitBook
On this page
Edit on GitHub
  1. Cookbook

Streaming Export API

PreviousInserting images into spreadsheets

Last updated 7 days ago

CtrlK
  • Why Streaming?
  • Usage in the Browser
  • Usage in NodeJS
  • Supported Features
  • See Also

Streaming export is designed for large datasets, providing better performance and memory efficiency in both browser and NodeJS environments. The API and features are the same as the regular export, all the features like formulas, alignments, borders, and everything else are all supported.

Why Streaming?

Traditional export methods generate the entire Excel file in memory, which can hang the browser or consume excessive resources for large datasets. Streaming solves this by generating and delivering the file in chunks.

Usage in the Browser

Use createExcelFileStream to export data as a stream. You can process chunks and update progress as needed.

import { createWorkbook, createExcelFileStream } from 'excel-builder-vanilla';

const workbook = createWorkbook();
const worksheet = workbook.createWorksheet({ name: 'Demo' });
worksheet.setData([

Usage in NodeJS

Streaming in NodeJS works similarly, but you can pipe the output directly to a file stream.

import fs from 'node:fs';
import { createWorkbook, createExcelFileStream } from 'excel-builder-vanilla';

const workbook = createWorkbook();
// ... add data and worksheets

const output = fs.createWriteStream('output.xlsx');
for await (const chunk of createExcelFileStream(workbook, { chunkSize: 1000 })) {
  output.write(chunk);
}
output.end();

Note: some NodeJS scripts can be found in the packages/demo/node-examples/ folder.

Supported Features

All features such as formulas, alignments, borders, styles, and images work with streaming export. The only difference is how the file is delivered.

See Also

  • Formulas

  • Alignment

  • Borders

  • Tables

['Artist', 'Album', 'Price'],
['Buckethead', 'Albino Slug', 8.99],
// ... more rows
]);
workbook.addWorksheet(worksheet);
const stream = createExcelFileStream(workbook, { chunkSize: 1000 });
const chunks: Uint8Array[] = [];
for await (const chunk of stream as AsyncIterable<Uint8Array>) {
chunks.push(chunk);
// Optionally update progress bar here
}
const blob = new Blob(chunks, { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
const url = URL.createObjectURL(blob);
// Download with anchor tag
Headers/Footers