From 3a6ab80ae8d1879c59f2f741b57442024a09afb4 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Tue, 11 Oct 2022 00:46:01 -0400 Subject: [PATCH] compression --- docz/docs/02-getting-started/02-example.mdx | 16 +++++++++------- docz/docs/09-miscellany/02-errors.md | 9 +++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/docz/docs/02-getting-started/02-example.mdx b/docz/docs/02-getting-started/02-example.mdx index 9ee4c73..95b6174 100644 --- a/docz/docs/02-getting-started/02-example.mdx +++ b/docz/docs/02-getting-started/02-example.mdx @@ -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 ( ); } ``` @@ -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 })); })(); @@ -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 })); ``` @@ -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 })); ``` diff --git a/docz/docs/09-miscellany/02-errors.md b/docz/docs/09-miscellany/02-errors.md index 233af9d..ba92a96 100644 --- a/docz/docs/09-miscellany/02-errors.md +++ b/docz/docs/09-miscellany/02-errors.md @@ -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