exceljs
exceljs copied to clipboard
Generate large file
What is the recommended way to export large file?
export async function export(ctx: koa.Context) {
ctx.response.attachment("report.xlsx")
ctx.status = 200
const workbook = new Excel.Workbook()
const worksheet = workbook.addWorksheet("report")
worksheet.columns = [
{ header: 'Id', key: 'id', width: 10 },
{ header: 'Name', key: 'name', width: 32 },
{ header: 'D.O.B.', key: 'DOB', width: 10, outlineLevel: 1 }
];
// million rows
for(const row of fetchDataFromDatabaseWithCursor()){
await worksheet.addRow(row);
}
await workbook.xlsx.write(ctx.res)
ctx.res.end()
}
I have a code like the above mentioned script , I want to send file data to user in for
loop too , not at the end of loop
How can I do it? if I move workbook.xlsx.write
into loop it create only 1 row
same issue
@sm2017 did you resolve it after 4 years :D