exceljs icon indicating copy to clipboard operation
exceljs copied to clipboard

Generate large file

Open sm2017 opened this issue 4 years ago • 1 comments

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

sm2017 avatar Oct 24 '19 09:10 sm2017

same issue

dtboy1995 avatar Jun 06 '22 06:06 dtboy1995

@sm2017 did you resolve it after 4 years :D

huy-lv avatar Oct 30 '23 06:10 huy-lv