exceljs icon indicating copy to clipboard operation
exceljs copied to clipboard

Support Stream writing in browser

Open jiridudekusy opened this issue 5 years ago • 11 comments

🚀 Stream writing should be possible in browser

If you export large excel file in browser, it crashes on memory. Stream writing which is supported in NodeJS should be supported in browser.

Required changes:

  • update node-compress-commons to use duck typing to identify Stream instead of "instanceof" Release: https://github.com/jiridudekusy/node-compress-commons/releases/tag/v2.1.1-browser
  • update archiver-utils to use duck typing to identify Stream instead of "instanceof" Release: https://github.com/jiridudekusy/archiver-utils/releases/tag/v2.1.0-browser
  • update exceljs to use Buffer.isBuffer instead of "instanceof" Release: https://github.com/jiridudekusy/exceljs/releases/tag/v3.8.2-stream-browser1

jiridudekusy avatar Apr 20 '20 21:04 jiridudekusy

I would also like this capability! I have an Angular app that display data in a grid and I need to export that data to excel. This works without any issues for small files using FileSaver.js and the workbook.xlsx.writeBuffer() method. But large exports (40+ columns and 100K+ rows), writeBuffer errors out and streaming does not seem to work in the browser (I am using StreamSaver.js for this).

ChristopherDuda avatar Aug 10 '20 22:08 ChristopherDuda

is there any status on this ?

vegarringdal avatar Jan 23 '21 18:01 vegarringdal

@ChristopherDuda How do you use streamsave.js btw ? Do you have some sample code?

vegarringdal avatar Jan 23 '21 20:01 vegarringdal

found it...

if anyone else wonders

import streamSaver from 'streamsaver'
const fileStream = streamSaver.createWriteStream('filename.xlsx', {
  writableStrategy: undefined, // (optional)
  readableStrategy: undefined  // (optional)
})
const writer = fileStream.getWriter()
workbook.xlsx.write(writer).then(()=>{
  writer.close()
})
    ```

vegarringdal avatar Jan 23 '21 20:01 vegarringdal

@ChristopherDuda

Did you have a better way ? Looks like it take a while...

vegarringdal avatar Jan 23 '21 21:01 vegarringdal

Is there any progress?

The sample code written by @vegarringdal works fine but, it doesn't seem to work for TS. The error message is like below.

[tsl] ERROR in .../Excel.vue.ts(32,23)
      TS2345: Argument of type 'WritableStreamDefaultWriter<any>' is not assignable to parameter of type 'Stream'.
  Type 'WritableStreamDefaultWriter<any>' is missing the following properties from type 'Stream': pipe, addListener, on, once, and 12 more.

imbyungjun avatar May 25 '21 07:05 imbyungjun

@vegarringdal https://codesandbox.io/s/use-streamsaver-to-save-file-kjrxh?file=/src/index.js

XiaoBai-Game avatar Aug 30 '21 07:08 XiaoBai-Game

@ddaylucifer 👍 Cool thx, Ill save this for later, not using exceljs for saving files. Have you tried reading files? Remember that was really slow too.

vegarringdal avatar Sep 01 '21 13:09 vegarringdal

@vegarringdal I only use '\t' and '\r\n' to write(steamSaver.writer.write) Excel in the reader loop,when the reader is done use steamSaver.write.close,steamSaver has good example

ps:You can include '\t' and '\r\n' directly in the string stream,so just write into excel

XiaoBai-Game avatar Sep 01 '21 18:09 XiaoBai-Game

@XiaoBai-Game

@vegarringdal https://codesandbox.io/s/use-streamsaver-to-save-file-kjrxh?file=/src/index.js

hi, brother. can your code handle large data set without OOM ?

AlwaysNoobCoder avatar Apr 23 '24 09:04 AlwaysNoobCoder

4 years....later.

any updates ?

AlwaysNoobCoder avatar Apr 23 '24 10:04 AlwaysNoobCoder