Closed tqdo closed 2 years ago
"Export to ZIP" is not really well defined. Excel / Google Sheets / Numbers don't have a canonical ZIP export.
If you wanted to export every worksheet as CSV in a ZIP container, this is doable with the embedded CFB dependency:
var zip = XLSX.CFB.utils.cfb_new()
wb.SheetNames.forEach((name,idx) => {
var csv = XLSX.utils.sheet_to_csv(wb.Sheets[name]);
XLSX.CFB.utils.cfb_add(zip, `sheet${idx+1}.csv`, new TextEncoder().encode(csv));
});
var data = XLSX.CFB.write(zip, {fileType: "zip"});
In NodeJS, that generates a Buffer
which you can write to file with fs.writeFileSync
. In the browser, that generates a Uint8Array
which you can download using the standard HTML5 download technique.
Note: XLSX/XLSB/ODS/Numbers are supported export formats that ultimately use a ZIP container.
Hi, just wondering whether there is a way to export to a .zip file instead of .xlsx? Thanks