From e455737c3319b2b1c76c30d7ced8eb5435b9b0fd Mon Sep 17 00:00:00 2001 From: SheetJS Date: Sat, 4 Nov 2023 01:05:26 -0400 Subject: [PATCH] vtl --- .../01-installation/07-bun.md | 12 +- docz/docs/03-demos/02-grid/12-vtl.md | 8 +- .../03-demos/03-net/02-server/11-nestjs.md | 2 +- docz/docs/03-demos/08-local/01-file.md | 15 ++- .../03-demos/32-extensions/09-mathematica.md | 114 ++++++++++++++++-- docz/docs/03-demos/42-engines/01-duktape.md | 2 +- docz/docs/03-demos/42-engines/09-hermes.md | 64 ++++++++-- docz/docs/03-demos/42-engines/20-chakra.md | 30 +++-- docz/docs/03-demos/42-engines/21-boa.md | 2 +- docz/docs/07-csf/07-features/06-nf.md | 2 +- docz/static/mathematica/SheetJSImportFile.png | Bin 0 -> 134583 bytes .../mathematica/SheetJSImportFileEE.png | Bin 0 -> 118918 bytes docz/static/mathematica/SheetJSImportURL.png | Bin 0 -> 144048 bytes docz/static/vtl/App.vue | 12 +- 14 files changed, 212 insertions(+), 51 deletions(-) create mode 100644 docz/static/mathematica/SheetJSImportFile.png create mode 100644 docz/static/mathematica/SheetJSImportFileEE.png create mode 100644 docz/static/mathematica/SheetJSImportURL.png diff --git a/docz/docs/02-getting-started/01-installation/07-bun.md b/docz/docs/02-getting-started/01-installation/07-bun.md index b1d24b0..cb0e973 100644 --- a/docz/docs/02-getting-started/01-installation/07-bun.md +++ b/docz/docs/02-getting-started/01-installation/07-bun.md @@ -89,9 +89,9 @@ XLSX.set_cptable(cpexcel); For server-side scripts, `bun build` can pre-optimize dependencies. The Bun builder requires a proper `package.json` that includes the SheetJS dependency. -:::note +:::note Tested Deployments -This example was last tested on 2023 October 21 against BunJS 1.0.6. +This example was last tested on 2023 November 05 against BunJS 1.0.8. ::: @@ -124,10 +124,14 @@ const url = "https://sheetjs.com/data/executive.json"; const raw_data = await (await fetch(url)).json(); /* filter for the Presidents */ -const prez = raw_data.filter((row) => row.terms.some((term) => term.type === "prez")); +const prez = raw_data.filter(row => row.terms.some(term => term.type === "prez")); + +/* sort by first presidential term */ +prez.forEach(row => row.start = row.terms.find(term => term.type === "prez").start); +prez.sort((l,r) => l.start.localeCompare(r.start)); /* flatten objects */ -const rows = prez.map((row) => ({ +const rows = prez.map(row => ({ name: row.name.first + " " + row.name.last, birthday: row.bio.birthday })); diff --git a/docz/docs/03-demos/02-grid/12-vtl.md b/docz/docs/03-demos/02-grid/12-vtl.md index 1ed06d9..73d9f4b 100644 --- a/docz/docs/03-demos/02-grid/12-vtl.md +++ b/docz/docs/03-demos/02-grid/12-vtl.md @@ -7,10 +7,10 @@ pagination_next: demos/net/index import current from '/version.js'; import CodeBlock from '@theme/CodeBlock'; -:::note +:::note Tested Deployments -This demo was tested against `vue3-table-lite 1.2.4`, VueJS `3.3.4`, ViteJS -4.4.7, and `@vitejs/plugin-vue` 4.2.3 on 2023 July 27 +This demo was tested against `vue3-table-lite 1.3.9`, VueJS `3.3.7` and ViteJS +`4.5.0` on 2023 November 03. ::: @@ -132,4 +132,4 @@ npm run dev 5) Load the displayed URL (typically `http://localhost:5173`) in a web browser. When the page loads, it will try to fetch -and display the data +and display the data. Click "Export" to generate a workbook. diff --git a/docz/docs/03-demos/03-net/02-server/11-nestjs.md b/docz/docs/03-demos/03-net/02-server/11-nestjs.md index 549c9d1..0782103 100644 --- a/docz/docs/03-demos/03-net/02-server/11-nestjs.md +++ b/docz/docs/03-demos/03-net/02-server/11-nestjs.md @@ -185,7 +185,7 @@ export class SheetjsController { npx @nestjs/cli start ``` -:::note +:::note pass In the most recent test, the process failed with a message referencing Multer: diff --git a/docz/docs/03-demos/08-local/01-file.md b/docz/docs/03-demos/08-local/01-file.md index a79bdb8..723bab7 100644 --- a/docz/docs/03-demos/08-local/01-file.md +++ b/docz/docs/03-demos/08-local/01-file.md @@ -440,9 +440,20 @@ When this demo was last tested, Google Chrome did not add an entry to the ::: -:::note +:::note Tested Deployments -This demo was last tested on 2023 August 30 in Google Chrome. +This browser demo was tested in the following environments: + +| Browser | Date | +|:------------|:-----------| +| Chrome 119 | 2023-11-04 | + +Some lesser-used browsers do not support File System Access API: + +| Browser | Date | +|:------------|:-----------| +| Safari 17.0 | 2023-11-04 | +| Firefox 119 | 2023-11-04 | ::: diff --git a/docz/docs/03-demos/32-extensions/09-mathematica.md b/docz/docs/03-demos/32-extensions/09-mathematica.md index a01f484..8043d16 100644 --- a/docz/docs/03-demos/32-extensions/09-mathematica.md +++ b/docz/docs/03-demos/32-extensions/09-mathematica.md @@ -7,6 +7,8 @@ pagination_next: demos/bigdata/index --- import current from '/version.js'; +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; import CodeBlock from '@theme/CodeBlock'; [Mathematica](https://mathematica.com) is a software system for mathematics and @@ -19,9 +21,9 @@ This demo uses SheetJS to pull data from a spreadsheet for further analysis within Mathematica. We'll explore how to run an external tool to generate CSV data from opaque spreadsheets and parse the data from Mathematica. -:::note +:::note Tested Deployments -This demo was last tested by SheetJS users on 2023 August 21 in Mathematica 13. +This demo was last tested by SheetJS users on 2023 November 04 in Mathematica 13. ::: @@ -74,6 +76,35 @@ _Complete Function_ The following function reads a file, parses the first worksheet and returns a Dataset object assuming one header row. + + + +```mathematica title="Complete Function" +(* Import file stored in the Documents folder (e.g. C:\Users\Me\Documents) *) +SheetJSImportFileEE[filename_]:=Module[{csv}, ( + (* This was required in local testing *) + RegisterExternalEvaluator["NodeJS","/usr/local/bin/node"]; + + (* Generate CSV from first sheet *) + csv:=ExternalEvaluate["NodeJS", StringJoin[ + (* module installed in home directory *) + "var XLSX = require('xlsx');", + (* read specified filename *) + "var wb = XLSX.readFile('",filename,"');", + (* grab first worksheet *) + "var ws = wb.Sheets[wb.SheetNames[0]];", + (* convert to CSV *) + "XLSX.utils.sheet_to_csv(ws)" + ]]; + + (* Parse CSV into a dataset *) + Return[ImportString[csv, "Dataset", "HeaderLines"->1]]; +)] +``` + + + + ```mathematica title="Complete Function" (* Import file stored in the Documents folder (e.g. C:\Users\Me\Documents) *) SheetJSImportFileEE[filename_]:=Module[{csv}, ( @@ -93,19 +124,22 @@ SheetJSImportFileEE[filename_]:=Module[{csv}, ( ]]; (* Parse CSV into a dataset *) - ImportString[csv, "Dataset", "HeaderLines"->1]; + Return[ImportString[csv, "Dataset", "HeaderLines"->1]]; )] ``` + + +
How to run the example (click to hide) -:::note +:::note Tested Deployments -This example was last tested on 2023 September 13 with Mathematica 13.3. +This example was last tested on 2023 November 04 with Mathematica 13.3. ::: -0) Install NodeJS. When the demo was tested, version `18.14.1` was installed. +0) Install NodeJS. When the demo was tested, version `20.9.0` was installed. 1) Install dependencies in the Home folder (`~` or `$HOME` or `%HOMEPATH%`): @@ -116,11 +150,25 @@ npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz zeromq@ 2) Open a new Mathematica Notebook and register NodeJS. When the example was tested in Windows, the commands were: + + + +```mathematica +RegisterExternalEvaluator["NodeJS","/usr/local/bin/node"] +FindExternalEvaluators["NodeJS"] +``` + + + + ```mathematica RegisterExternalEvaluator["NodeJS","C:\\Program Files\\nodejs\\node.exe"] FindExternalEvaluators["NodeJS"] ``` + + + The second argument to `RegisterExternalEvaluator` should be the path to the `node` or `node.exe` binary. @@ -143,6 +191,8 @@ to the base folder as shown in the previous step. SheetJSImportFileEE["pres.numbers"] ``` +![SheetJSImportFileEE result](pathname:///mathematica/SheetJSImportFileEE.png) +
### Command-Line Tools @@ -183,21 +233,17 @@ flowchart LR ## Complete Demo -:::info pass - -This demo was tested in macOS. The path names will differ in other platforms. - -::: - 1) Create the standalone `xlsx-cli` binary[^14]: {`\ -cd /tmp npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz exit-on-epipe commander@2 curl -LO https://docs.sheetjs.com/cli/xlsx-cli.js npx nexe -t 14.15.3 xlsx-cli.js`} + + + 2) Move the generated `xlsx-cli` to a fixed location in `/usr/local/bin`: ```bash @@ -205,6 +251,20 @@ mkdir -p /usr/local/bin mv xlsx-cli /usr/local/bin/ ``` + + + +2) Find the current directory: + +```bash +cd +``` + +The generated binary will be `xlsx-cli.exe` in the displayed path. + + + + ### Reading a Local File 3) In a new Mathematica notebook, run the following snippet: @@ -212,10 +272,34 @@ mv xlsx-cli /usr/local/bin/ ```mathematica SheetJSImportFile[x_] := ImportString[Block[{Print}, ExternalEvaluate[ "Shell" -> "StandardOutput", + // highlight-next-line "/usr/local/bin/xlsx-cli " <> x ]], "Dataset", "HeaderLines" -> 1] ``` + + + + + + +Change `/usr/local/bin/xlsx-cli` in the string to the path to the generated +`xlsx-cli.exe` binary. For example, if the path in step 2 was +`C:\Users\Me\Documents\`, then the code should be: + +```mathematica +SheetJSImportFile[x_] := ImportString[Block[{Print}, ExternalEvaluate[ + "Shell" -> "StandardOutput", + // highlight-next-line + "C:\\Users\\Me\\Documents\\xlsx-cli.exe " <> x +]], "Dataset", "HeaderLines" -> 1] +``` + +The `\` characters must be doubled. + + + + 4) Download and save to Downloads folder: ```bash @@ -232,6 +316,8 @@ data = SheetJSImportFile["~/Downloads/pres.numbers"] The result should be displayed in a concise table. +![SheetJSImportFile result](pathname:///mathematica/SheetJSImportFile.png) + ### Reading from a URL `FetchURL`[^15] downloads a file from a specified URL and returns a path to the @@ -253,6 +339,8 @@ SheetJSImportURL[x_] := Module[{path},( data = SheetJSImportURL["https://sheetjs.com/pres.numbers"] ``` +![SheetJSImportURL result](pathname:///mathematica/SheetJSImportURL.png) + [^1]: See [the `ExternalEvaluate` Node.js example](https://reference.wolfram.com/language/ref/ExternalEvaluate.html#:~:text=Evaluate%20a%20basic%20math%20function%20in%20JavaScript%20using%20Node.js%3A) in the Mathematica documentation. [^2]: See [`RegisterExternalEvaluator`](https://reference.wolfram.com/language/ref/RegisterExternalEvaluator.html) in the Mathematica documentation. [^3]: See [`ExternalEvaluate`](https://reference.wolfram.com/language/ref/ExternalEvaluate.html) in the Mathematica documentation. diff --git a/docz/docs/03-demos/42-engines/01-duktape.md b/docz/docs/03-demos/42-engines/01-duktape.md index 63f5f6a..c2436d3 100644 --- a/docz/docs/03-demos/42-engines/01-duktape.md +++ b/docz/docs/03-demos/42-engines/01-duktape.md @@ -229,7 +229,7 @@ curl -LO https://docs.sheetjs.com/duk/sheetjs.duk.c gcc -std=c99 -Wall -osheetjs.duk sheetjs.duk.c duktape.c -lm ``` -:::note +:::note pass GCC may generate a warning: diff --git a/docz/docs/03-demos/42-engines/09-hermes.md b/docz/docs/03-demos/42-engines/09-hermes.md index e0dbaa9..5a8bc51 100644 --- a/docz/docs/03-demos/42-engines/09-hermes.md +++ b/docz/docs/03-demos/42-engines/09-hermes.md @@ -356,7 +356,7 @@ while the "CLI Test" demonstrates other concepts using the `hermes` CLI tool. ### Integration Example -:::note +:::note Tested Deployments This demo was tested in the following deployments: @@ -374,6 +374,8 @@ fork, which powers React Native for Windows, does have built-in support[^5] |:-------------|:-----------|:-----------| | `win10-x64` | `930456b` | 2023-10-28 | +The ["Windows Example"](#windows-example) covers `hermes-windows`. + ::: 0) Install [dependencies](https://hermesengine.dev/docs/building-and-running/#dependencies) @@ -627,18 +629,56 @@ contents of the first sheet as CSV rows. ### CLI Test -:::note +:::note Tested Deployments -This demo was last tested on 2023 August 27 against Hermes version `0.11.0`. +This demo was last tested on 2023 November 04 against Hermes version `0.11.0`. ::: Due to limitations of the standalone binary, this demo will encode a test file as a Base64 string and directly add it to an amalgamated script. -0) Install the `hermes` command line tool +#### Install CLI -1) Download the SheetJS Standalone script and the test file. Save both files in +0) Install the Hermes command line tools: + +```bash +npx jsvu install hermes@0.11.0 +``` + +When prompted, select the appropriate operating system. + +1) Inspect the output of the installer. Look for "Installing binary" lines: + +```text pass +❯ Extracting… +// highlight-next-line +Installing binary to ~/.jsvu/engines/hermes-0.11.0/hermes-0.11.0… +Installing symlink at ~/.jsvu/bin/hermes-0.11.0 pointing to ~/.jsvu/engines/hermes-0.11.0/hermes-0.11.0… +Installing binary to ~/.jsvu/engines/hermes-0.11.0/hermes-0.11.0-compiler… +Installing symlink at ~/.jsvu/bin/hermes-0.11.0-compiler pointing to ~/.jsvu/engines/hermes-0.11.0/hermes-0.11.0-compiler… +``` + +The first "Installing binary" line mentions the path to the `hermes` tool. + +#### Setup Project + +2) Create a new project folder: + +```bash +mkdir sheetjs-hermes-cli +cd sheetjs-hermes-cli +``` + +3) Copy the binary from Step 1 into the current folder. For example, on macOS: + +```bash +cp ~/.jsvu/engines/hermes-0.11.0/hermes-0.11.0 . +``` + +#### Create Script + +4) Download the SheetJS Standalone script and the test file. Save both files in the project directory: