xsheetjs/demos/extendscript
2022-05-20 04:56:18 -04:00
..
.gitignore version bump 0.12.0: extendscript fixes 2018-02-08 13:21:39 -05:00
aftereffects.base version bump 0.9.6 2017-03-25 18:18:50 -04:00
aftereffects.jsx version bump 0.12.2: BIFF2-4 features 2018-02-21 02:10:33 -05:00
estoolkit.base version bump 0.9.6 2017-03-25 18:18:50 -04:00
estoolkit.jsx version bump 0.12.2: BIFF2-4 features 2018-02-21 02:10:33 -05:00
illustrator.base version bump 0.9.6 2017-03-25 18:18:50 -04:00
illustrator.jsx version bump 0.12.2: BIFF2-4 features 2018-02-21 02:10:33 -05:00
indesign.base version bump 0.9.6 2017-03-25 18:18:50 -04:00
indesign.jsx version bump 0.12.2: BIFF2-4 features 2018-02-21 02:10:33 -05:00
Makefile version bump 0.12.0: extendscript fixes 2018-02-08 13:21:39 -05:00
photoshop.base version bump 0.9.6 2017-03-25 18:18:50 -04:00
photoshop.jsx version bump 0.12.2: BIFF2-4 features 2018-02-21 02:10:33 -05:00
README.md estk test [ci skip] 2022-05-20 04:56:18 -04:00
sheetjs.xlsx version bump 0.9.6 2017-03-25 18:18:50 -04:00
test.jsx version bump 0.12.2: BIFF2-4 features 2018-02-21 02:10:33 -05:00

Adobe ExtendScript

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 to wherever you want the scripts to reside.

ExtendScript Quirks

There are numerous quirks in ExtendScript code parsing, especially related to Boolean and bit operations. Most JS tooling will generate code that is not compatible with ExtendScript. It is highly recommended to #include the dist file directly and avoid trying to minify or pack as part of a larger project.

File I/O

Using the "binary" encoding, file operations will work with binary strings that play nice with the "binary" type of this library. The readFile and writeFile library functions wrap the File logic:

/* Read file from disk */
var workbook = XLSX.readFile(filename);

/* Write file to disk */
XLSX.writeFile(workbook, filename);
Implementation Details (click to show)

The readFile and writeFile functions use "binary" encoding under the hood:

/* Read file from disk without using readFile */
var infile = File(filename);
infile.open("r");
infile.encoding = "binary";
var data = infile.read();
var workbook = XLSX.read(data, {type:"binary"});
infile.close();

/* Write file to disk without using writeFile */
var outFile = File(filename);
outFile.open("w");
outFile.encoding = "binary";
outFile.write(workbook);
outFile.close();

Demo

The demo shows:

  • loading the library in ExtendScript using #include:
#include "xlsx.extendscript.js"
  • opening a file with XLSX.readFile:
var workbook = XLSX.readFile("sheetjs.xlsx");
  • converting a worksheet to an array of arrays:
var first_sheet_name = workbook.SheetNames[0];
var first_worksheet = workbook.Sheets[first_sheet_name];
var data = XLSX.utils.sheet_to_json(first_worksheet, {header:1});

alert(data);
  • writing a new workbook file:
XLSX.writeFile(workbook, "sheetjs.slk");

Analytics