This commit is contained in:
SheetJS 2023-04-14 04:13:40 -04:00
parent 2e540f5b15
commit 866ebabc68
6 changed files with 93 additions and 47 deletions

@ -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.
<details><summary><b>Complete Example</b> (click to show)</summary>
@ -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';
```
:::
<details><summary><b>Complete Example</b> (click to show)</summary>
1) Install the tarball using a package manager:

@ -230,7 +230,8 @@ then restart the development process.
<q-file label="Load File" filled label-color="orange" @input="updateFile"/>
<q-btn label="Save File" @click="saveFile" />
</q-btn-group>
<!-- highlight-end --> </q-page>
<!-- highlight-end -->
</q-page>
</template>
```

@ -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`.
<details><summary><b>Complete Example</b> (click to show)</summary>
<https://docs.sheetjs.com/cli/sheet2csv.ts> 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 <filename> [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 <https://sheetjs.com/pres.numbers>:
```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`:
</details>
```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

@ -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`.

@ -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`
</TabItem>
<TabItem value="l" label="Linux">
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.
:::
</TabItem>

@ -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 <filename> [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]));