Streaming Export API
Last updated
Last updated
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.
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.
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([
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.
All features such as formulas, alignments, borders, styles, and images work with streaming export. The only difference is how the file is delivered.