using js-xlsx inside adobe extendscript #603
Labels
No Label
DBF
Dates
Defined Names
Features
Formula
HTML
Images
Infrastructure
Integration
International
ODS
Operations
Performance
PivotTables
Pro
Protection
Read Bug
SSF
SYLK
Style
Write Bug
good first issue
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#603
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Is it possible to include the js-xlsx library and scripts inside adobe JavaScript environment ?
Can i include js-xlsx in a non web application ?
Need an advise for resources on this topic.
Thank you all for keeping this place active.
@firas3d if it is a standard JS runtime, you should be able to add the
shim.js
anddist/xlsx.core.min.js
and it should just work. The library works in IE6, so I assume it'll work elsewhere.If you need international support (like Chinese/Japanese/Korean characters), use
dist/xlsx.full.min.js
.I don't think any of the devs are familiar with extend script so it would be helpful if you can produce a small demo that loads the script. And if it does work, please add a note in the wiki :)
Thanks @reviewher, will do my best tonight to load the shim.js and xlsx.core.min.js
Which funtion/method can i use that permits to read a cell or a range ?
If we access xlsx inside adobe extedscript, then that would be awesome achievement to all adobe workflow. (Currently all adobe tools developers are converting tables to text files, but you can imagine how its unfriendly for data visualizations)
You need to somehow "get the file" then "read it".
https://github.com/SheetJS/js-xlsx#parsing-workbooks has some examples. I'm not sure how extend script works but they probably some function to read a file into a string or array. Once you have that, you can call
XLSX.read
and it will give you a workbook object. Options are described in https://github.com/SheetJS/js-xlsx#parsing-options . The most important one istype
which tells the library how the data was encoded (as a string or array): https://github.com/SheetJS/js-xlsx#input-typeXLSX.read
will return a workbook object. The format is described in the README: https://github.com/SheetJS/js-xlsx#workbook--worksheet--cell-object-descriptionThere are some utilities for converting to JS objects. For example, to convert the first worksheet to an array of arrays like
[["A1","B1","C1"],["A2","B2","C2"],["A3","B3","C3"]]
:I am facing errors in lines scripts format, for example "expected: ;"
The xlsx.core.min.js has no new-lines, all code is one block of text :( thats make it difficult to read.
thanks.
Hello @firas3d ! Thanks for looking into this!
For development purposes, include the following files in order:
shim.js
jszip.js
xlsx.flow.js
They are all unminified so you should have a useful line number
Appreciate the help from a more experienced developer.
I couldnt include the js files without getting strange errors.
Can anyone help by downloading the adobe extendedscript and
http://www.adobe.com/mena_en/products/extendscript-toolkit.html
Big thanks,
Firas.
There were a few issues with the shims assuming that
self
existed, as well as a strange regexp bug (apparently you can't start a regular expression literal with=
). I made the requisite changes toshim.js
andjszip.js
here: https://gist.github.com/SheetJSDev/449989cd7b47b5c5d8a8a2d829b368c0The ExtendScript I tested was:
and it appeared to work:
Download the shim.js and jszip.js files from the link and see if those work. Once that works, try reading the file in (as a binary string or byte array or whatever extendscript does) and call
XLSX.read(data)
Big thanks @SheetJSDev , an error xlsx.flow.js when calling
XLSX.readFile('test.xlsx');
Appreciate 👍
Updated the jszip script, new file at https://gist.github.com/SheetJSDev/5573c7c02c47421b17185a73dc5497f6 -- long story short, none of the usual global suspects (global, window, self) are available, so you have to poke a hole in
app
to pass back variables from#include
'd scriptsHere's some sample code to read
sheetjs.xlsx
For future reference: the guide is available at https://www.adobe.com/content/dam/Adobe/en/devnet/scripting/pdfs/javascript_tools_guide.pdf
File
is the extendscript object for reading files. To read as a binary string, set the encoding to"binary"
and then read the file.Test it out and let us know if it works!
not working on my side yet,
i guess my xlsx.flow.js is different than yours.
Can you zip the 3 files ? shim.js, jszip.js and xlsx.flow.js
extend.zip
for good measure I also included the test file I was using and the test.jsx file.
I can actually reproduce that error, it's most likely coming because extendscript is looking in the wrong directory. To test this, in the javascript console run
Folder.current
. If it doesn't show the directory where sheetjs.xlsx resides, either changeFolder.current
in the console OR change the filename variable to the full path of the excel file (error only occurs in OSX; in windows, if you double-click the test.jsx file, extendscript toolkit automatically sets the working directory)yes, reopened extendscript, and all works fine.
again, appreciate your help.
I wonder when do you sleep?
If you find any other issues, let us know. Going to close this issue and take a nap :)
small issu when connecting target application.
All works fine if target is ExtendScript Toolkit CC
But if it is changed to Adobe Illustrator for example, or adding
#target illustrator
line, the errorError : jszip does not have a constructor
inside xlsx.flow.js
So I downloaded a trial of Illustrator CC 2017 for OSX and I can't reproduce. It also works if i remove the
target
line and use Photoshop CC 2017.Are you on windows or mac? Also, can you add the line
alert(JSZip)
right after thevar JSZip = app.JSZip;
and see that it is being loaded?with
#target illustrator
alert(JSZip);
without
#target illustrator
a working script :
alert(JSZip);
using windows10
@firas3d just to be sure: if you take out the line
#target illustrator
but manually change the target app toAdobe Illustrator CC 2017
, do you see the first or second popup?same, wither i put the line #target or link it from interface, the problem occur.
from what i understand, the JSZip library doesnt like #target application
but when i run the script from Adobe Illustrator (not from Adobe ExtendScipt toolkit) , it works fine.
@firas3d we made some changes to the shim and jszip scripts. Please update both
jszip.js
andshim.js
. We included a new test.jsx in the extendscript demo directorysuper, will test it,
The #target app problem was showing on one machine only, so i guess all good.