diff --git a/docz/docs/04-getting-started/03-demos/02-extendscript.md b/docz/docs/04-getting-started/03-demos/02-extendscript.md new file mode 100644 index 0000000..c12764d --- /dev/null +++ b/docz/docs/04-getting-started/03-demos/02-extendscript.md @@ -0,0 +1,190 @@ +--- +sidebar_position: 3 +--- + +# Adobe Apps + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +Photoshop, InDesign and other Adobe Creative Suite applications offer extension +support. Over the years there have been a few different JavaScript platforms: + +- "ExtendScript": This uses an old JavaScript dialect but is supported in older + versions of Creative Suite and Creative Cloud. + +- "CEP": This was recommended in CS6 but eventually deprecated. + +- "UXP": This is the current Adobe recommendation for new CC extensions. + +This demo intends to cover the SheetJS-related parts. General setup as well as +general Adobe considerations are not covered here. A basic familiarity with +extension development is assumed. + +## ExtendScript Scripts + +[Installation is straightforward:](../../installation/extendscript) download a +script and move it to your project directory. + +### Reading Files + +`XLSX.readFile` can directly accept an absolute URI: + +```js +var workbook = XLSX.readFile("~/Documents/test.xlsx"); +``` + +The path can be user-configurable using `File.openDialog`: + +```js +/* Show File Picker */ +var thisFile = File.openDialog("Select a spreadsheet"); +if(!thisFile) { alert("File not found!"); return; } + +/* Read file from disk */ +var workbook = XLSX.readFile(thisFile.absoluteURI); +``` + +
Complete Example (click to hide) + +In this example, the script will show a dialog to select a file. After reading +the file, the workbook Author property will be extracted and the Photoshop doc +author (`activeDocument.info.author`) will be changed accordingly. + +This demo was verified in Photoshop CS6 64-bit on Windows 10. + +```js +#target photoshop +#include "xlsx.extendscript.js"; + +function main_parse() { + /* Show File Picker */ + var thisFile = File.openDialog("Select a spreadsheet"); + if(!thisFile) { alert("File not found!"); return; } + + /* Read file from disk */ + var workbook = XLSX.readFile(thisFile.absoluteURI); + + /* Get Workbook Author */ + var Props = workbook.Props; if(!Props) { alert("Missing Author!"); return; } + var Author = Props.Author; if(!Author) { alert("Missing Author!"); return; } + + /* Change Document Author to Workbook Author */ + var info = activeDocument.info; + alert("Changing Author from |" + info.author + "| to |" + Author + "|"); + info.author = Author; +} + +main_parse(); +``` + +0) Download the [test workbook](pathname:///files/SheetJS.xlsb). + +1) Download the following scripts: +- [`xlsx.extendscript.js`](https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.extendscript.js) +- [`parse.jsx`](pathname:///live/parse.jsx) + +and place in the scripts directory. For CS6 Windows 10 the path is typically + +`C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)\Presets\Scripts` + +2) Restart Photoshop and open a file (or create a new one) + +3) File > Scripts > parse and select the test workbook + +4) An alert will confirm that the file was read and the author will be changed: + +!["Changing Author" popup](pathname:///files/psparse.png) + +5) File > File Info... should show the updated Author field! + +
+ +### Writing Files + +`XLSX.writeFile` can directly accept an absolute URI: + +```js +XLSX.writeFile(workbook, "~/Documents/test.xlsx"); +``` + +The path can be user-configurable using `File.saveDialog`: + +```js +/* Show File Picker */ +var thisFile = File.saveDialog("Select an output file", "*.xlsx;*.xls"); +if(!thisFile) { alert("File not found!"); return; } + +/* Write file to disk */ +XLSX.writeFile(workbook, thisFile.absoluteURI); +``` + +
Complete Example (click to hide) + +In this example, the script will show a dialog to select an output file. Once +selected, the library will create a new workbook with one worksheet. Cell A1 +will be "Author" and cell B1 will be the active Photoshop document Author. +The PS author is available as `activeDocument.info.author`. + +This demo was verified in Photoshop CS6 64-bit on Windows 10. + +```js +#target photoshop +#include "xlsx.extendscript.js"; + +function main_write() { + /* Show File Picker */ + var thisFile = File.saveDialog("Select an output file", "*.xlsx;*.xls"); + if(!thisFile) { alert("File not found!"); return; } + + /* Create new Worksheet */ + var ws = XLSX.utils.aoa_to_sheet([ + ["Author", activeDocument.info.author] + ]); + + /* Create new Workbook and add worksheet */ + var wb = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(wb, ws, "Sheet1"); + + /* Write file to disk */ + XLSX.writeFile(wb, thisFile.absoluteURI); + alert("Created File " + thisFile.absoluteURI); +} + +main_write(); +``` + +1) Download the following scripts: +- [`xlsx.extendscript.js`](https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.extendscript.js) +- [`write.jsx`](pathname:///live/write.jsx) + +and place in the scripts directory. For CS6 Windows 10 the path is typically + +`C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)\Presets\Scripts` + +2) Restart Photoshop and open a file (or create a new one) + +3) File > File Info ... and confirm there is an Author. If not, set to `SheetJS` + +4) File > Scripts > write and use the popup to select the Documents folder. + Enter `SheetJSPSTest.xlsx` and hit "Save" + +4) An alert will confirm that the file was created: + +!["Created File" popup](pathname:///files/pswrite.png) + +5) Open the generated `SheetJSPSTest.xlsx` file and compare to Photoshop author + +
+ +## CEP + +[The standalone scripts](../../installation/standalone) can be added to CEP +extension HTML + +## UXP + +UXP officially recommends `require` and NodeJS Modules for third party support. + +[Use the "Frameworks" instructions to download.](../../installation/frameworks) + diff --git a/docz/docs/04-getting-started/03-demos/index.md b/docz/docs/04-getting-started/03-demos/index.md index 888f974..dd63162 100644 --- a/docz/docs/04-getting-started/03-demos/index.md +++ b/docz/docs/04-getting-started/03-demos/index.md @@ -33,7 +33,7 @@ The demo projects include small runnable examples and short explainers. - [`NW.js`](https://github.com/SheetJS/SheetJS/tree/master/demos/nwjs/) - [`Chrome / Chromium Extension`](https://github.com/SheetJS/SheetJS/tree/master/demos/chrome/) - [`Google Sheets API`](./gsheet) -- [`ExtendScript for Adobe Apps`](https://github.com/SheetJS/SheetJS/tree/master/demos/extendscript/) +- [`ExtendScript for Adobe Apps`](./extendscript) - [`Headless Browsers`](https://github.com/SheetJS/SheetJS/tree/master/demos/headless/) - [`Other JavaScript Engines`](https://github.com/SheetJS/SheetJS/tree/master/demos/altjs/) - [`"serverless" functions`](https://github.com/SheetJS/SheetJS/tree/master/demos/function/) diff --git a/docz/docs/06-solutions/01-input.md b/docz/docs/06-solutions/01-input.md index 69372bc..f45eea3 100644 --- a/docz/docs/06-solutions/01-input.md +++ b/docz/docs/06-solutions/01-input.md @@ -338,7 +338,7 @@ request({url: url, encoding: null}, function(err, resp, body) { }); ``` -[`axios`](https://npm.im/axios) works the same way in browser and in NodeJS: +[`axios`](https://axios-http.com/) works the same way in browser and in NodeJS: ```js const XLSX = require("xlsx"); diff --git a/docz/docs/06-solutions/05-output.md b/docz/docs/06-solutions/05-output.md index 34d2c4d..0899885 100644 --- a/docz/docs/06-solutions/05-output.md +++ b/docz/docs/06-solutions/05-output.md @@ -296,10 +296,10 @@ data grid for previewing and modifying structured data in the web browser. The
Previewing data in a React data grid (click to show) -[`react-data-grid`](https://npm.im/react-data-grid) is a data grid tailored for -react. It expects two properties: `rows` of data objects and `columns` which -describe the columns. For the purposes of massaging the data to fit the react -data grid API it is easiest to start from an array of arrays. +[`react-data-grid`](https://adazzle.github.io/react-data-grid) is a data grid +built for React. It uses two properties: `rows` of data objects and `columns` +which describe the columns. For the purposes of massaging the data to fit the +`react-data-grid` API it is easiest to start from an array of arrays. This demo starts by fetching a remote file and using `XLSX.read` to extract: @@ -336,8 +336,9 @@ export default function App() {
Previewing data in a VueJS data grid (click to show) -[`vue3-table-lite`](https://github.com/linmasahiro/vue3-table-lite) is a simple -VueJS 3 data table. It is featured [in the VueJS demo](https://github.com/SheetJS/SheetJS/tree/master/demos/vue/modify/). +[`vue3-table-lite`](https://linmasahiro.github.io/vue3-table-lite/dist/) is a +simple VueJS 3 data table. It is featured in the +[VueJS demo](https://github.com/SheetJS/SheetJS/tree/master/demos/vue/modify/).
diff --git a/docz/docs/07-csf/03-book.md b/docz/docs/07-csf/03-book.md index c7de881..ee9065c 100644 --- a/docz/docs/07-csf/03-book.md +++ b/docz/docs/07-csf/03-book.md @@ -67,9 +67,9 @@ XLSX.write(wb, {Props:{Author:"SheetJS"}});
Format Support (click to show) -**Defined Names**: XLSX/M, XLSB, BIFF8 XLS, XLML, SYLK +**Simple Defined Names**: XLSX/M, XLSB, BIFF8 XLS, XLML, ODS, SYLK -**Unicode Defined Names**: XLSX/M, XLSB, BIFF8 XLS, XLML +**Unicode Defined Names**: XLSX/M, XLSB, BIFF8 XLS, XLML, ODS **Defined Name Comment**: XLSX/M, XLSB, BIFF8 XLS diff --git a/docz/docs/index.md b/docz/docs/index.md index 45e8f57..217c568 100644 --- a/docz/docs/index.md +++ b/docz/docs/index.md @@ -8,7 +8,7 @@ hide_table_of_contents: true ![License](https://img.shields.io/github/license/SheetJS/sheetjs) [![Build Status](https://img.shields.io/github/workflow/status/sheetjs/sheetjs/Tests:%20node.js)](https://github.com/SheetJS/sheetjs/actions) [![Snyk Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/SheetJS/sheetjs)](https://snyk.io/test/github/SheetJS/sheetjs) -[![npm Downloads](https://img.shields.io/npm/dm/xlsx.svg)](https://npmjs.org/package/xlsx) +[![npm Downloads](https://img.shields.io/npm/dm/xlsx.svg)](https://cdn.sheetjs.com/) SheetJS Community Edition offers battle-tested open-source solutions for extracting useful data from almost any complex spreadsheet and generating new @@ -67,7 +67,7 @@ document.getElementById("sheetjsexport").addEventListener('click', function() { function Table2XLSX(props) { /* Callback invoked when the button is clicked */ - const xport = React.useCallback(() => { + const xport = React.useCallback(async () => { /* Create worksheet from HTML DOM TABLE */ const table = document.getElementById("Table2XLSX"); const wb = XLSX.utils.table_to_book(table); diff --git a/docz/static/files/SheetJS.xlsb b/docz/static/files/SheetJS.xlsb new file mode 100644 index 0000000..c8f8ff0 Binary files /dev/null and b/docz/static/files/SheetJS.xlsb differ diff --git a/docz/static/files/psparse.png b/docz/static/files/psparse.png new file mode 100644 index 0000000..11e56ff Binary files /dev/null and b/docz/static/files/psparse.png differ diff --git a/docz/static/files/pswrite.png b/docz/static/files/pswrite.png new file mode 100644 index 0000000..4a793f5 Binary files /dev/null and b/docz/static/files/pswrite.png differ diff --git a/docz/static/live/parse.jsx b/docz/static/live/parse.jsx new file mode 100644 index 0000000..e9269b7 --- /dev/null +++ b/docz/static/live/parse.jsx @@ -0,0 +1,22 @@ +#target photoshop +#include "xlsx.extendscript.js"; + +function main_parse() { + /* Show File Picker */ + var thisFile = File.openDialog("Select a spreadsheet"); + if(!thisFile) { alert("File not found!"); return; } + + /* Read file from disk */ + var workbook = XLSX.readFile(thisFile.absoluteURI); + + /* Get Workbook Author */ + var Props = workbook.Props; if(!Props) { alert("Missing Author!"); return; } + var Author = Props.Author; if(!Author) { alert("Missing Author!"); return; } + + /* Change Document Author to Workbook Author */ + var info = activeDocument.info; + alert("Changing Author from |" + info.author + "| to |" + Author + "|"); + info.author = Author; +} + +main_parse(); \ No newline at end of file diff --git a/docz/static/live/write.jsx b/docz/static/live/write.jsx new file mode 100644 index 0000000..97794a2 --- /dev/null +++ b/docz/static/live/write.jsx @@ -0,0 +1,23 @@ +#target photoshop +#include "xlsx.extendscript.js"; + +function main_write() { + /* Show File Picker */ + var thisFile = File.saveDialog("Select an output file", "*.xlsx;*.xls"); + if(!thisFile) { alert("File not found!"); return; } + + /* Create new Worksheet */ + var ws = XLSX.utils.aoa_to_sheet([ + ["Author", activeDocument.info.author] + ]); + + /* Create new Workbook and add worksheet */ + var wb = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(wb, ws, "Sheet1"); + + /* Write file to disk */ + XLSX.writeFile(wb, thisFile.absoluteURI); + alert("Created File " + thisFile.absoluteURI); +} + +main_write(); \ No newline at end of file