From b7d3eae3b7a02de1d03f0e627140c616443e40b0 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Fri, 20 May 2022 04:56:18 -0400 Subject: [PATCH] estk test [ci skip] --- demos/README.md | 3 +- demos/datagrid/README.md | 2 +- demos/extendscript/README.md | 5 ++- demos/fusebox/.gitignore | 4 -- demos/fusebox/Makefile | 17 -------- demos/fusebox/README.md | 62 ---------------------------- demos/fusebox/fuse.js | 26 ------------ demos/fusebox/index.html | 36 ---------------- demos/fusebox/sheetjs.ts | 28 ------------- demos/google-sheet/README.md | 73 +++------------------------------ demos/google-sheet/index.js | 17 -------- demos/google-sheet/package.json | 13 ------ demos/xspreadsheet/README.md | 2 +- estk.jsx | 45 ++++++++++++++++++++ 14 files changed, 57 insertions(+), 276 deletions(-) delete mode 100644 demos/fusebox/.gitignore delete mode 100644 demos/fusebox/Makefile delete mode 100644 demos/fusebox/README.md delete mode 100644 demos/fusebox/fuse.js delete mode 100644 demos/fusebox/index.html delete mode 100644 demos/fusebox/sheetjs.ts delete mode 100644 demos/google-sheet/index.js delete mode 100644 demos/google-sheet/package.json create mode 100644 estk.jsx diff --git a/demos/README.md b/demos/README.md index 15be429..187077e 100644 --- a/demos/README.md +++ b/demos/README.md @@ -31,7 +31,6 @@ can be installed with Bash on Windows or with `cygwin`. **Bundlers and Tooling** - [`browserify`](browserify/) -- [`fusebox`](fusebox/) - [`parcel`](parcel/) - [`requirejs`](requirejs/) - [`rollup`](rollup/) @@ -44,7 +43,7 @@ can be installed with Bash on Windows or with `cygwin`. - [`electron application`](electron/) - [`nw.js application`](nwjs/) - [`Chrome / Chromium extensions`](chrome/) -- [`Download a Google Sheet locally`](google-sheet/) +- [`Google Sheets API`](https://docs.sheetjs.com/docs/getting-started/demos/gsheet) - [`Adobe ExtendScript`](extendscript/) - [`Headless Browsers`](headless/) - [`canvas-datagrid`](datagrid/) diff --git a/demos/datagrid/README.md b/demos/datagrid/README.md index d27617d..f367779 100644 --- a/demos/datagrid/README.md +++ b/demos/datagrid/README.md @@ -10,7 +10,7 @@ This demo is available at ## Obtaining the Library The `canvas-datagrid` NodeJS packages include a minified script that can be -directly inserted as a script tag. The unpkg CDN also hosts this script: +directly inserted as a script tag. The unpkg CDN also serves this script: ```html diff --git a/demos/extendscript/README.md b/demos/extendscript/README.md index 6ec287e..6a8c6e5 100644 --- a/demos/extendscript/README.md +++ b/demos/extendscript/README.md @@ -4,7 +4,7 @@ ExtendScript adds some features to a limited form of ECMAScript version 3. With the included shim, the library can run within Photoshop and other Adobe apps! The main file is `test.jsx`. Target-specific files prepend target directives. -Copy the `test.jsx` file as well as the `xlsx.extendscript.js` library script +Copy the `test.jsx` file as well as the `xlsx.extendscript.js` library script to wherever you want the scripts to reside. @@ -30,6 +30,8 @@ var workbook = XLSX.readFile(filename); XLSX.writeFile(workbook, filename); ``` +
Implementation Details (click to show) + The `readFile` and `writeFile` functions use `"binary"` encoding under the hood: @@ -50,6 +52,7 @@ outFile.write(workbook); outFile.close(); ``` +
## Demo diff --git a/demos/fusebox/.gitignore b/demos/fusebox/.gitignore deleted file mode 100644 index 15c6fa7..0000000 --- a/demos/fusebox/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.fusebox -tsconfig.json -client.js -server.js diff --git a/demos/fusebox/Makefile b/demos/fusebox/Makefile deleted file mode 100644 index fcae7f4..0000000 --- a/demos/fusebox/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -.PHONY: all -all server.js client.js: fuse.js - node fuse.js - -.PHONY: test ctest -test: server.js - @node server.js - xlsx --dev sheetjsfbox.xlsb - -ctest: client.js - python -mSimpleHTTPServer - -.PHONY: init -init: - mkdir -p node_modules - cd node_modules; ln -s ../../../ xlsx; cd - - diff --git a/demos/fusebox/README.md b/demos/fusebox/README.md deleted file mode 100644 index 424be6c..0000000 --- a/demos/fusebox/README.md +++ /dev/null @@ -1,62 +0,0 @@ -# FuseBox - -This library is built with some dynamic logic to determine if it is invoked in a -script tag or in nodejs. FuseBox does not understand those feature tests, so by -default it will do some strange things. - -## TypeScript Support - -As with most TS modules in FuseBox, the glob import form should be used: - -```typescript -import * as XLSX from 'xlsx'; -``` - -The included `sheetjs.ts` script will be transpiled and bundled to `server.js` -for the `"node"` target and `client.js` for the `"browser"` target. - -## Proper Target Detection - -Out of the box, FuseBox will automatically provide shims to browser globals like -`process` and `Browser`. The proper way to detect `node` uses `process`: - -```typescript -if(typeof process != 'undefined' && process.versions && process.versions.node) { - /* Script is running in nodejs */ -} else { - /* Script is running in a browser environment */ -} -``` - -## Server Target - -The FuseBox documentation configuration can be used as-is: - -```js -const fuse = FuseBox.init({ - homeDir: ".", - target: "node", - output: "$name.js" -}); -fuse.bundle("server").instructions(">sheetjs.ts"); fuse.run(); -``` - -## Browser Target - -The native shims must be suppressed for browser usage: - -```js -const fuse = FuseBox.init({ - homeDir: ".", - target: "browser", - natives: { - Buffer: false, - stream: false, - process: false - }, - output: "$name.js" -}); -fuse.bundle("client").instructions(">sheetjs.ts"); fuse.run(); -``` - -[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.com/SheetJS/js-xlsx) diff --git a/demos/fusebox/fuse.js b/demos/fusebox/fuse.js deleted file mode 100644 index fe9fc02..0000000 --- a/demos/fusebox/fuse.js +++ /dev/null @@ -1,26 +0,0 @@ -const { FuseBox } = require("fuse-box"); -const common_opts = { - homeDir: ".", - output: "$name.js" -}; - -const browser_opts = { - target: "browser", - natives: { - Buffer: false, - stream: false, - process: false - }, - ...common_opts -}; - -const node_opts = { - target: "node", - ...common_opts -} - -const fuse1 = FuseBox.init(browser_opts); -fuse1.bundle("client").instructions(">sheetjs.ts"); fuse1.run(); - -const fuse2 = FuseBox.init(node_opts); -fuse2.bundle("server").instructions(">sheetjs.ts"); fuse2.run(); diff --git a/demos/fusebox/index.html b/demos/fusebox/index.html deleted file mode 100644 index 90dcdb8..0000000 --- a/demos/fusebox/index.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - -SheetJS FuseBox Test - - - -
-SheetJS FuseBox Demo
-
-Source Code Repo
-Issues?  Something look weird?  Click here and report an issue
-
-Original script: sheetjs.ts
-
-Console Output:
-
-

-
-
-
-
-
diff --git a/demos/fusebox/sheetjs.ts b/demos/fusebox/sheetjs.ts
deleted file mode 100644
index 7de1ec4..0000000
--- a/demos/fusebox/sheetjs.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import * as XLSX from 'xlsx';
-
-console.log(XLSX.version);
-
-const bookType: string = "xlsb";
-const fn: string = "sheetjsfbox." + bookType
-const sn: string = "SheetJSFBox";
-const aoa: any[][] = [ ["Sheet", "JS"], ["Fuse", "Box"], [72, 62] ];
-
-
-var wb: XLSX.WorkBook = XLSX.utils.book_new();
-var ws: XLSX.WorkSheet = XLSX.utils.aoa_to_sheet(aoa);
-XLSX.utils.book_append_sheet(wb, ws, sn);
-
-var payload: string = "";
-var w2: XLSX.WorkBook;
-if(typeof process != 'undefined' && process.versions && process.versions.node) {
-	/* server */
-	XLSX.writeFile(wb, fn);
-	w2 = XLSX.readFile(fn)
-} else {
-	/* client */
-	payload = XLSX.write(wb, {bookType: "xlsb", type:"binary"});
-	w2 = XLSX.read(payload, {type:"binary"});
-}
-
-var s2: XLSX.WorkSheet = w2.Sheets[sn];
-console.log(XLSX.utils.sheet_to_csv(s2));
diff --git a/demos/google-sheet/README.md b/demos/google-sheet/README.md
index b865029..02a19c6 100644
--- a/demos/google-sheet/README.md
+++ b/demos/google-sheet/README.md
@@ -1,72 +1,9 @@
-# Google Sheet Demo
+# Google Sheets API
 
-This demo is using [`drive-db`](https://github.com/franciscop/drive-db) to fetch a public Google Sheet and then `xlsx` to save the data locally as `test.xlsx`.
+The old demo used a deprecated version of the Google Sheets API to export data
+from Google Sheets Documents.
 
-It uses modern Javascript; `import/export`, `async/away`, etc. To run this you need Node.js 12 or newer, and you will notice we added `"type": "module"` to the `package.json`.
-
-Here is the full code:
-
-```js
-import xlsx from "xlsx";
-import drive from "drive-db";
-
-(async () => {
-  const data = await drive("1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k");
-
-  /* Create a new workbook */
-  const workbook = xlsx.utils.book_new();
-
-  /* make worksheet */
-  const worksheet = xlsx.utils.json_to_sheet(data);
-
-  /* Add the worksheet to the workbook */
-  xlsx.utils.book_append_sheet(workbook, worksheet);
-
-  xlsx.writeFile(workbook, "test.xlsx");
-})();
-```
-
-Let's go over the different parts:
-
-```js
-import xlsx from "xlsx";
-import drive from "drive-db";
-```
-
-This imports both `xlsx` and `drive-db` libraries. While these are written in commonjs, Javascript Modules can usually import the commonjs modules with no problem.
-
-```js
-(async () => {
-  // ...
-})();
-```
-
-
-This is what is called an [Immediately Invoked Function Expression](https://flaviocopes.com/javascript-iife/). These are normally used to either create a new execution context, or in this case to allow to run async code easier.
-
-```js
-const data = await drive("1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k");
-```
-
-Using `drive-db`, fetch the data for the given spreadsheet id. In this case it's [this Google Sheet document](https://docs.google.com/spreadsheets/d/1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k/edit), and since we don't specify the sheet it's the default one.
-
-```js
-const workbook = xlsx.utils.book_new();
-const worksheet = xlsx.utils.json_to_sheet(data);
-```
-
-We need to create a workbook with a worksheet inside. The worksheet is created from the previously fetched data. `drive-db` exports the data in the same format that `xlsx`'s `.json_to_sheet()` method expects, so it's a straightforward operation.
-
-```js
-xlsx.utils.book_append_sheet(workbook, worksheet);
-```
-
-The worksheet needs to be inside the workbook, so we use the operation `.book_append_sheet()` to make it so.
-
-```js
-xlsx.writeFile(workbook, "test.xlsx");
-```
-
-Finally we save the workbook into a XLSX file in out filesystem. With this, now it can be opened by any spreadsheet program that we have installed.
+[The new demo](https://docs.sheetjs.com/docs/getting-started/demos/gsheet) uses
+the new Google Sheets API to read and write data.
 
 [![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.com/SheetJS/js-xlsx)
diff --git a/demos/google-sheet/index.js b/demos/google-sheet/index.js
deleted file mode 100644
index 2e657b1..0000000
--- a/demos/google-sheet/index.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import xlsx from "xlsx";
-import drive from "drive-db";
-
-(async () => {
-  const data = await drive("1fvz34wY6phWDJsuIneqvOoZRPfo6CfJyPg1BYgHt59k");
-
-  /* Create a new workbook */
-  const workbook = xlsx.utils.book_new();
-
-  /* make worksheet */
-  const worksheet = xlsx.utils.json_to_sheet(data);
-
-  /* Add the worksheet to the workbook */
-  xlsx.utils.book_append_sheet(workbook, worksheet);
-
-  xlsx.writeFile(workbook, "test.xlsx");
-})();
diff --git a/demos/google-sheet/package.json b/demos/google-sheet/package.json
deleted file mode 100644
index d8e7d34..0000000
--- a/demos/google-sheet/package.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
-  "name": "google-sheet",
-  "version": "1.0.0",
-  "description": " This demo is using 'drive-db' to fetch a public Google Sheet and then `xlsx` to save the data locally as test.xlsx",
-  "main": "index.js",
-  "type": "module",
-  "scripts": {
-    "start": "node ."
-  },
-  "keywords": [],
-  "author": "Francisco Presencia  (https://francisco.io/)",
-  "license": "MIT"
-}
diff --git a/demos/xspreadsheet/README.md b/demos/xspreadsheet/README.md
index 22f364f..2321769 100644
--- a/demos/xspreadsheet/README.md
+++ b/demos/xspreadsheet/README.md
@@ -10,7 +10,7 @@ This demo is available at 
 ## Obtaining the Library
 
 The `x-data-spreadsheet` NodeJS packages include a minified script that can be
-directly inserted as a script tag.  The unpkg CDN also hosts this script:
+directly inserted as a script tag.  The unpkg CDN also serves this script:
 
 ```html
 
diff --git a/estk.jsx b/estk.jsx
new file mode 100644
index 0000000..5af5699
--- /dev/null
+++ b/estk.jsx
@@ -0,0 +1,45 @@
+#target estoolkit
+var thisFile = new File($.fileName);
+var basePath = thisFile.path;
+
+#include "dist/xlsx.extendscript.js";
+
+var filename = "/sheetjs.xlsx";
+
+/* Read file from disk */
+var workbook = XLSX.readFile(basePath + filename, {cellDates:true});
+
+/* Display first worksheet */
+var first_sheet_name = workbook.SheetNames[0], first_worksheet = workbook.Sheets[first_sheet_name];
+var data = XLSX.utils.sheet_to_json(first_worksheet, {header:1});
+alert(data);
+
+var outfmts = [
+  ["xlsb",  "testw.xlsb"],
+  ["biff8", "testw.xls"],
+  ["xlml",  "testw.xml"],
+  ["fods",  "testw.fods"],
+  ["csv",   "testw.csv"],
+  ["txt",   "testw.txt"],
+  ["slk",   "testw.slk"],
+  ["eth",   "testw.eth"],
+  ["htm",   "testw.htm"],
+  ["dif",   "testw.dif"],
+  ["ods",   "testw.ods"],
+  ["xlsx",  "testw.xlsx"]
+];
+for(var i = 0; i < outfmts.length; ++i) {
+  alert(outfmts[i][0]);
+  var fname = basePath + "/" + outfmts[i][1];
+
+  /* Write file to disk */
+  XLSX.writeFile(workbook, fname);
+
+  /* Read new file */
+  var wb = XLSX.readFile(fname, {cellDates:true});
+
+  /* Display first worksheet */
+  var f_sheet_name = wb.SheetNames[0], f_worksheet = wb.Sheets[f_sheet_name];
+  var data = XLSX.utils.sheet_to_json(f_worksheet, {header:1, cellDates:true});
+  alert(data);
+}
\ No newline at end of file