Description
ExcelJs does not finish properly when using stream buffer like this:
@options.workbookOpts = {
# filename: 'tmp/test.xlsx',
# stream: @outputStream,
useStyles: true,
useSharedStrings: true
};
@workbook = new Excel.stream.xlsx.WorkbookWriter @options.workbookOpts
@worksheet = @workbook.addWorksheet('WSName')
@workbook.stream.pipe(@outputStream)
## add some rows
@workbook.commit()
.then (res) =>
console.log("END")
On this line https://github.com/guyonroche/exceljs/blob/master/lib/stream/xlsx/workbook-writer.js#L320 you are listening for finish
event which is correct for writeStreams (based on node.js doc: https://nodejs.org/api/stream.html#stream_event_finish)
But here in the StreamBuf
class you are emitting end
event instead:
https://github.com/guyonroche/exceljs/blob/master/lib/utils/stream-buf.js#L287
Possible solutions are:
-
Emit
finish
event instead. (Or emit bothend
andfinish
events?)
PR: Fire finish event instead of end event on write stream #199 -
Don't listen for events on StreamBuf but on zipStream instead.
PR: Listen for finish event on zip stream instead of middle stream #200
Sideinfo: end
event is on readStreams instead.
Workaround: is to use stream: --writeStream--
option instead of piping (in my code it is commented out).