From 866ebabc68ddf9637216b03454ca9e5924ff1ea6 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Fri, 14 Apr 2023 04:13:40 -0400 Subject: [PATCH] ventura --- docz/docs/03-demos/01-frontend/08-bundler.md | 31 ++++++++----- docz/docs/03-demos/05-mobile/03-quasar.md | 3 +- docz/docs/03-demos/06-desktop/09-cli.md | 49 +++++++------------- docz/docs/09-miscellany/02-errors.md | 22 +++++++++ docz/docs/09-miscellany/05-contributing.md | 11 ++++- docz/static/cli/sheet2csv.ts | 24 ++++++++++ 6 files changed, 93 insertions(+), 47 deletions(-) create mode 100644 docz/static/cli/sheet2csv.ts diff --git a/docz/docs/03-demos/01-frontend/08-bundler.md b/docz/docs/03-demos/01-frontend/08-bundler.md index 9e69f91..0471eb8 100644 --- a/docz/docs/03-demos/01-frontend/08-bundler.md +++ b/docz/docs/03-demos/01-frontend/08-bundler.md @@ -182,8 +182,8 @@ Complete Examples are included [in the "Dojo" demo](/docs/demos/frontend/legacy# ## esbuild -The `xlsx.mjs` source file are written in a subset of ES6 that `esbuild` -understands and is able to transpile down for older browsers. +The `xlsx.mjs` source file uses a subset of ES6 that `esbuild` understands and +is able to transpile for older browsers. Both the `node` and `browser` platforms work out of the box. @@ -971,15 +971,7 @@ As it uses `fetch`, this demo requires Node 18. ## Vite -:::caution - -ViteJS adopted nascent `package.json` patterns. Version 0.18.10 implements the -patterns required for ViteJS 3.0.3. These patterns are evolving and a future -version of ViteJS may require more packaging changes. - -::: - -ViteJS 3.0.3 is known to work with SheetJS version 0.18.10. +ViteJS is compatible with SheetJS versions starting from 0.18.10.
Complete Example (click to show) @@ -1095,6 +1087,23 @@ set_cptable(cptable); ::: +:::caution + +Some older webpack projects will throw an error in the browser: + +``` +require is not defined (xlsx.mjs) +``` + +This was a bug in Webpack and affected projects built with `create-react-app`. +If upgrading Webpack is not feasible, explicitly import the standalone builds: + +```js +import * as XLSX from 'xlsx/dist/xlsx.full.min.js'; +``` + +::: +
Complete Example (click to show) 1) Install the tarball using a package manager: diff --git a/docz/docs/03-demos/05-mobile/03-quasar.md b/docz/docs/03-demos/05-mobile/03-quasar.md index 68b4d7f..61ed0a7 100644 --- a/docz/docs/03-demos/05-mobile/03-quasar.md +++ b/docz/docs/03-demos/05-mobile/03-quasar.md @@ -230,7 +230,8 @@ then restart the development process. - + + ``` diff --git a/docz/docs/03-demos/06-desktop/09-cli.md b/docz/docs/03-demos/06-desktop/09-cli.md index a01c620..fcc51be 100644 --- a/docz/docs/03-demos/06-desktop/09-cli.md +++ b/docz/docs/03-demos/06-desktop/09-cli.md @@ -24,45 +24,28 @@ runtime as well as user JS code. When compiling, the `--allow-read` option must be specified to allow the script to read files from the filesystem with `Deno.readFileSync`. -
Complete Example (click to show) + can be compiled and run from Deno: -1) Save the following script to `sheet2csv.ts`: - -```ts title="sheet2csv.ts" -/*! sheetjs (C) 2013-present SheetJS -- https://sheetjs.com */ -// @deno-types="https://cdn.sheetjs.com/xlsx-latest/package/types/index.d.ts" -import * as XLSX from 'https://cdn.sheetjs.com/xlsx-latest/package/xlsx.mjs'; -import * as cptable from 'https://cdn.sheetjs.com/xlsx-latest/package/dist/cpexcel.full.mjs'; -XLSX.set_cptable(cptable); - -/* Read and parse workbook */ -const filename = Deno.args[0]; -if(!filename) { - console.error("usage: sheet2csv [sheetname]"); - Deno.exit(1); -} -const workbook = XLSX.readFile(filename); - -/* Find worksheet */ -const sheetname = Deno.args[1] || workbook.SheetNames[0]; -if(!workbook.Sheets[sheetname]) { - console.error(`error: workbook missing sheet ${sheetname}`); - Deno.exit(1); -} - -/* Generate CSV and print to stdout */ -console.log(XLSX.utils.sheet_to_csv(workbook.Sheets[sheetname])); -``` - -2) Build `sheet2csv` with `deno compile`: +0) Download the test file : ```bash -deno compile -r --allow-read sheet2csv.ts +curl -LO https://sheetjs.com/pres.numbers ``` -`sheet2csv` is a generated executable that you can run. +1) Test the script with `deno run`: -
+```bash +deno run -r --allow-read https://docs.sheetjs.com/cli/sheet2csv.ts pres.numbers +``` + +If this worked, the program will print a CSV of the first worksheet. + +2) Compile and run `sheet2csv`: + +```bash +deno compile -r --allow-read https://docs.sheetjs.com/cli/sheet2csv.ts +./sheet2csv pres.numbers +``` ## NodeJS diff --git a/docz/docs/09-miscellany/02-errors.md b/docz/docs/09-miscellany/02-errors.md index fa39c98..c4172f1 100644 --- a/docz/docs/09-miscellany/02-errors.md +++ b/docz/docs/09-miscellany/02-errors.md @@ -148,6 +148,28 @@ export default { }; ``` +#### "require is not defined" + +This error will be displayed in the browser console and will point to `xlsx.mjs` + +Older versions of Webpack do not support `mjs` for ECMAScript Modules. This +typically affects older `create-react-app` projects. + +[The "Standalone" build](/docs/getting-started/installation/standalone) should +be loaded using `require` or `import`: + +_CommonJS_ + +```js +var XLSX = require("xlsx/dist/xlsx.full.min"); +``` + +_ECMAScript Modules_ + +```js +import * as XLSX from "xlsx/dist/xlsx.full.min.js"; +``` + #### SCRIPT5022: DataCloneError IE10 does not properly support `Transferable`. diff --git a/docz/docs/09-miscellany/05-contributing.md b/docz/docs/09-miscellany/05-contributing.md index 6ad7bf5..422fc68 100644 --- a/docz/docs/09-miscellany/05-contributing.md +++ b/docz/docs/09-miscellany/05-contributing.md @@ -40,7 +40,9 @@ These instructions were tested on the following platforms: | Platform | Test Date | |:------------------------------|:-----------| | Linux (Steam Deck Holo 3.4.6) | 2023-04-04 | +| Linux (Ubuntu 18.04 aarch64) | 2023-04-13 | | MacOS 10.13 (x64) | 2023-04-04 | +| MacOS 13.0 (arm64) | 2023-04-13 | | Windows 10 (x64) + WSL Ubuntu | 2023-01-14 | | Windows 11 (x64) + WSL Ubuntu | 2023-04-04 | @@ -148,11 +150,12 @@ local testing, macOS 10.13 required NodeJS version `12.22.12` -A) Install `mercurial`, `git`, and `subversion` using the system package +A) Install `curl`, `mercurial`, `git`, and `subversion` using the system package manager. On Debian and Ubuntu systems, `apt-get` installs packages: ```bash -sudo apt-get install git mercurial subversion +sudo apt update +sudo apt-get install curl git mercurial subversion ``` Other Linux distributions may use other package managers. @@ -197,6 +200,10 @@ After installing mercurial and subversion, install NodeJS. [The official NodeJS site](https://nodejs.org/en/download/) provides installers for "LTS" and "Current" releases. The "LTS" version should be installed. +After installing, if running `node` in the terminal fails with a `glibc` error, +an older version of NodeJS should be installed. For example, Ubuntu 18.04 does +not support Node 18 support Node 16.20.0. + ::: diff --git a/docz/static/cli/sheet2csv.ts b/docz/static/cli/sheet2csv.ts new file mode 100644 index 0000000..a61988c --- /dev/null +++ b/docz/static/cli/sheet2csv.ts @@ -0,0 +1,24 @@ +#!/usr/bin/env -S deno run --allow-read +/*! sheetjs (C) 2013-present SheetJS -- https://sheetjs.com */ +// @deno-types="https://cdn.sheetjs.com/xlsx-latest/package/types/index.d.ts" +import * as XLSX from 'https://cdn.sheetjs.com/xlsx-latest/package/xlsx.mjs'; +import * as cptable from 'https://cdn.sheetjs.com/xlsx-latest/package/dist/cpexcel.full.mjs'; +XLSX.set_cptable(cptable); + +/* Read and parse workbook */ +const filename = Deno.args[0]; +if(!filename) { + console.error("usage: sheet2csv [sheetname]"); + Deno.exit(1); +} +const workbook = XLSX.readFile(filename); + +/* Find worksheet */ +const sheetname = Deno.args[1] || workbook.SheetNames[0]; +if(!workbook.Sheets[sheetname]) { + console.error(`error: workbook missing sheet ${sheetname}`); + Deno.exit(1); +} + +/* Generate CSV and print to stdout */ +console.log(XLSX.utils.sheet_to_csv(workbook.Sheets[sheetname]));