Sheetjs: Add support for streaming to xlsx or xlsb

Created on 16 Jul 2019  路  2Comments  路  Source: SheetJS/sheetjs

First of all, thanks for the library.

Second, I need support for streaming files to xlsx or xlsb
Currently there is the support for streaming files as csv, json and html, is there a workaround to do the same for xls?
I mean there is an option to save files as xlsx directly, so may be same can be used here?!

Thanks again.

Most helpful comment

It's extremely strange that there aren't streaming functions for all supported output formats

All 2 comments

Well, I found the functionality within the library, at least for my specific case.

I needed to pipe/stream xlsx object as blob or buffer to a client from my express server. And here is the code which I ended up using, as it turns out library provides in built support for buffer and expressJS can send a buffer successfully to the client.

response.setHeader('Content-Type', 'application/octet-stream');
response.setHeader('Content-Disposition', 'attachment; filename="File.xlsx"');

let data = JSON.parse(request.body.data);
var wb = XLSX.utils.book_new();
var ws = XLSX.utils.json_to_sheet(data);
XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
var wbopts = {
type: 'buffer',
bookType: "xlsx",
bookSST: false
};
var wbout = XLSX.write(wb, wbopts);
response.send(wbout);

In above code, I am writing a file to storage, Converting JSON to XLSX inside code, and client can save the result to file.

As for CSV, here is the code if again, someone wants it:

response.setHeader('Content-Type', 'application/octet-stream');
response.setHeader('Content-Disposition', 'attachment; filename="File.csv"');
....
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');

var stream = XLSX.stream.to_csv(ws);
stream.pipe(response);

Thanks @SheetJSDev again, for this great library.

It's extremely strange that there aren't streaming functions for all supported output formats

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seanmcilvenna picture seanmcilvenna  路  3Comments

DannyRyman picture DannyRyman  路  3Comments

thomasledoux1 picture thomasledoux1  路  3Comments

goxr3plus picture goxr3plus  路  3Comments

gustavosimil picture gustavosimil  路  3Comments