5 Replies Latest reply on Jul 25, 2017 7:05 PM by yasinkkhan

    Excel data to construct illustrator object

    Willis77019b Level 1


      How to read real number data from selected columns in an Excel spreadsheet into an illustrator javascript array variable, so that then I can use this information to construct an illustrator polygon. 


      Further information:

      I am new to javascript (and not much of a programmer in the best case, but do have some basic knowledge using ancient languages like FORTRAN 88). I am sure I am just missing an important step here despite all morning browsing with Google for answers (something to do with variable definition I assume?). I have some survey data defining the outline of features in map view listed in a string of point (x,y) values in adjacent columns in excel (these x,y point values calculated from GPS data using a commercial program to converted 3D position to a 2D x,y by geoid projection, and then in excel to re-scale point locations to illustrator’s artboard).  What I am trying to do is select columns of x,y value pairs in an excel spreadsheet, copy these values to the clipboard, and then develop an IA JavaScript to draw a polygon through the specified set of x,y points. It seems easy enough to script illustrator to draw the polygon once I get the values from the clipboard are in a javascript array (lots a good tips here http://scriptographer.org/tutorials/), but pulling in the clipboard data seems to be beyond me. I have tried populating a defined array with various combinations of array declarations and app.paste(); or windows.clipboardData.getData('text/plain'); with no satisfaction. I then had the idea to try to pull in the clipboard to one long continuous string, place that in a text box (see see its structure), andthen read and split up the text in a loop to populate the JavaScript array…but that deposited a complex illustrator table object into my text box, and several attempts to force the clipboard to paste text did not work (again probably having problems understanding variable type declaration).


      Thanks very much for any suggests….and to be clear, I would be happy to find any method of scripting the pull of the selected on an excel spreadsheet for use in an Illustrator script…so if I am making this all harder than it needs, be I would be grateful to know that also!

        • 1. Re: Excel data to construct illustrator object

          You can open Excel documents via the XML object. Excel docs are really just xml. If you rename a workbook.xlsx file to workbook.zip and unzip you will see all the worksheets as xml files. Open them up in your favorite editor and you will see the structure of the file.




          Also now that you know excel = xml, revise your google searches and look for how to bring in xml and how to access elements within the tree and you should be well on your way. If none of the expert scripters around here respond by tomorrow, I'll see if I can put a basic script that will get you started, but for now I need bed!

          • 2. Re: Excel data to construct illustrator object
            John Hawkinson Level 5

            I would tend to suggest you just export the relevant piece of the Excel workbook as a CSV file and read and open the CSV file in JavaScript. Clipboard is a pain, and digging inside Excel XML is even more of a pain.

            • 3. Re: Excel data to construct illustrator object
              pixxxel schubser Level 5


              At first you need a CSV-File or a tab-separated TXT (like in the follow example)




              Now you read this xyCoords.text and create your shape:


              // ShapeFromExcelSheet.jsx
              // regards pixxelschubser
              var aFile = File ("~/Desktop/TestFolder/xyCoords.txt");
              var coordFile = aFile.read();
              var xyList = coordFile.split("\n");
              var coords = new Array (xyList.length-1);
              for (i=0; i<xyList.length-1; i++) {
                  xy = xyList[i].split( "\t");
                  xy[0] = Number(xy[0]);
                  xy[1] = Number(xy[1]);
                  coords[i] = xy;
              // the following code based on:
              // TrapezPathCreate.jsx
              // http://forums.adobe.com/thread/1307731
              var aDoc = app.activeDocument;
              var aPath = aDoc.pathItems.add();
              aPath.name = "Trapez";
              //aPath.setEntirePath(Array([0,0],[50,100],[200,100],[400,0],[0,0])); //       this was the original code
              aPath.close = true;
              aPath.filled= true;
              aPath.stroked= false;
              var itemColor = new CMYKColor();
              itemColor.cyan = 0;
              itemColor.magenta = 100;
              itemColor.yellow = 100;
              itemColor.black = 0;
              aPath.fillColor = itemColor;


              Note that coordinates are used differently in the different versions of Illustrator.


              Have fun.

              • 4. Re: Excel data to construct illustrator object
                Willis77019b Level 1

                Many thanks for the input pixxxel schubser. Following your lead I did get it to paste, but only by an indirect copy route. Anyone else interested in this, my work flow was to transform map coordinates to illustrator coordinates in excel (a simple ratio calculation), copy from excel to notepad (to remove all but text), then copy from notepad and run the modified version of the script below. Copying it twice is an extra step, but at least it saves the time sorting out the files for each line segment.


                var aDoc = app.activeDocument;


                var coordpaste =app.activeDocument.selection[0];

                var coordtext = coordpaste.contents;

                var xyList = coordtext.split("\r");

                var coords = new Array (xyList.length-1);for (i=0; i<xyList.length-1; i++) {

                    xy = xyList[i].split( "\t");

                    xy[0] = Number(xy[0]);

                    xy[1] = Number(xy[1]);

                    coords[i] = xy;}

                var aPath = aDoc.pathItems.add();


                aPath.stroked= true;

                aPath.close = false;

                aPath.filled= false;



                1 person found this helpful
                • 5. Re: Excel data to construct illustrator object

                  THANK YOU !!! Totally solved a different excel related issue for me. I was trying to copy a whole bunch of rows of data (single column) into a single text box in illustrator, instead of many multiple ones. Copied from excel to text editor, then to illustrator and got it exactly how I wanted.