compression

This commit is contained in:
SheetJS 2022-10-11 00:46:01 -04:00
parent 10805cd4b3
commit 3a6ab80ae8
2 changed files with 18 additions and 7 deletions

@ -152,10 +152,12 @@ will always be in the `.xlsx` format. `writeFileXLSX` is more amenable to tree
shaking. This example uses `XLSX.writeFile` since `writeFileXLSX` does not
support other common export formats like `.xls` or `.xlsb` or `.csv`.
`compression: true` enables ZIP compression for XLSX and other formats.
:::
```js
XLSX.writeFile(workbook, "Presidents.xlsx");
XLSX.writeFile(workbook, "Presidents.xlsx", { compression: true });
```
![Final export](./img/final.png)
@ -191,7 +193,7 @@ function Presidents() { return ( <button onClick={async () => {
worksheet["!cols"] = [ { wch: max_width } ];
/* create an XLSX file and try to save to Presidents.xlsx */
XLSX.writeFile(workbook, "Presidents.xlsx");
XLSX.writeFile(workbook, "Presidents.xlsx", { compression: true });
}}><b>Click to Generate file!</b></button> ); }
```
@ -239,7 +241,7 @@ hosted (no `file:///` access).
worksheet["!cols"] = [ { wch: max_width } ];
/* create an XLSX file and try to save to Presidents.xlsx */
XLSX.writeFile(workbook, "Presidents.xlsx");
XLSX.writeFile(workbook, "Presidents.xlsx", { compression: true }));
})();
</script>
<body>
@ -285,7 +287,7 @@ const XLSX = require("xlsx");
worksheet["!cols"] = [ { wch: max_width } ];
/* create an XLSX file and try to save to Presidents.xlsx */
XLSX.writeFile(workbook, "Presidents.xlsx");
XLSX.writeFile(workbook, "Presidents.xlsx", { compression: true }));
})();
```
@ -336,7 +338,7 @@ const axios = require("axios");
worksheet["!cols"] = [ { wch: max_width } ];
/* create an XLSX file and try to save to Presidents.xlsx */
XLSX.writeFile(workbook, "Presidents.xlsx");
XLSX.writeFile(workbook, "Presidents.xlsx", { compression: true }));
})();
```
@ -378,7 +380,7 @@ const max_width = rows.reduce((w: number, r: any) => Math.max(w, r.name.length),
worksheet["!cols"] = [ { wch: max_width } ];
/* create an XLSX file and try to save to Presidents.xlsx */
XLSX.writeFile(workbook, "Presidents.xlsx");
XLSX.writeFile(workbook, "Presidents.xlsx", { compression: true }));
```
</TabItem>
@ -419,7 +421,7 @@ const max_width = rows.reduce((w, r) => Math.max(w, r.name.length), 10);
worksheet["!cols"] = [ { wch: max_width } ];
/* create an XLSX file and try to save to Presidents.xlsx */
XLSX.writeFile(workbook, "Presidents.xlsx");
XLSX.writeFile(workbook, "Presidents.xlsx", { compression: true }));
```
</TabItem>

@ -94,6 +94,15 @@ document.getElementById('file-object').addEventListener("change", function(e) {
## Data Issues
#### Generated XLSX files are very large!
By default, compression is disabled. Set the option `compression: true` in the
`write` or `writeFile` options object. For example:
```js
XLSX.writeFile(workbook, "export.xlsx", { compression: true });
```
#### CSV and XLS files with Chinese or Japanese characters look garbled
The ESM build, used in tools like Webpack and in Deno, does not include the