Files
wekan/server/lib/streamSheetWorkbook.js
T
Lauri Ojansivu db9c06dc5e monday.com, Businessmap and Wrike workbooks are streamed a page at a time too.
Every workbook export is now written by ExcelJS's streaming workbook
writer, a row at a time, instead of a whole workbook in memory.

- monday.com and Businessmap: one sheet each; the columns any card fills
  (monday.com's custom fields; Businessmap's optional columns, comment
  columns and other fields) and Businessmap's parent Card IDs are found
  over the whole board from the light first pass, the header written on
  the first page (server/lib/streamSheetWorkbook.js, shared).
- Wrike: the lanes' order, the folder rows and every row's Key are planned
  over the whole board (wrikePlan, wrikePageOrder); the pages come in that
  order and a lane's folder row goes before its first card. The date
  columns are date cells, as in the whole workbook.

tests/workbookStream.test.cjs checks every page size against the whole
sheet and reads each streamed workbook back as the whole one; the
import/export audit (173) and the admin-only custom field specs (12) pass.

Thanks to xet7 !
2026-11-20 11:41:28 +02:00

29 lines
1.2 KiB
JavaScript

// A one-sheet workbook written to `stream` a page at a time, from an async
// iterable of { sheets: [{ name, rows }] } pages (the formats that write their
// header on the first page: monday.com, Businessmap). ExcelJS's streaming
// writer commits each row as it comes, so only one page of rows is in memory;
// the header row is bold, as the whole writers make it.
async function streamSheetWorkbook(stream, pages) {
const ExcelJS = require('@wekanteam/exceljs');
const workbook = new ExcelJS.stream.xlsx.WorkbookWriter({ stream, useStyles: true });
let worksheet = null;
for await (const { sheets } of pages) {
const sheet = (sheets || [])[0] || { rows: [] };
let first = false;
if (!worksheet) {
worksheet = workbook.addWorksheet(String(sheet.name || 'sheet1').replace(/[\\/?*[\]:]/g, ' ').slice(0, 31) || 'sheet1');
first = true;
}
(sheet.rows || []).forEach((cells, index) => {
const row = worksheet.addRow(cells);
if (first && index === 0) row.font = { bold: true };
row.commit();
});
}
if (!worksheet) workbook.addWorksheet('sheet1');
else await worksheet.commit();
await workbook.commit();
}
module.exports = { streamSheetWorkbook };