3 Replies Latest reply on Nov 1, 2016 8:27 AM by TᴀW

    load excel spreadsheet to table variable?

    akiva_atwood

      I know how to create a doc, place an excel spreadsheet in the doc, and then refer to the cells of the table....

       

      Is it possible to skip the "create" and "place" steps -- and do something like

       

      myTable = new Table;

      myTable = open("path to excel file");

      myData=myTable.rows[2].cells[11].texts[0].contents;

        • 1. Re: load excel spreadsheet to table variable?
          Daniel Sterchi Adobe Community Professional

          Hi akiva_atwood

           

          Short answer: no…

           

          First you need to have a open document. Then you can place a spreadsheet which creates a table inside a text frame. Then you can get the data of a specific field.

           

          A bit of code:

          main();
          exit();
          
          
          function main() {
          
            // take the open document
            var myDoc = app.activeDocument;
          
            // take the first textframe in my example
            var myTextFrame = myDoc.textFrames[0];
          
            // take the first table of the first textframe. A table lives inside a textframe
            var myTable = myTextFrame.tables[0];
          
            // get the data from the cell (1,3)
            var myData = myTable.columns[1].cells[2].contents;
          
            // write the data to the console
            $.writeln(myData);
          }
          

           

          I hope this helps to answer your question

           

          kind regards

           

          Daniel

          (from Switzerland)

          • 2. Re: load excel spreadsheet to table variable?
            akiva_atwood Level 1

            Hi Daniel

             

            I know how to do it that way -- I was hoping to avoid the create and place steps.

             

            Thanks

             

            Akiva

            • 3. Re: load excel spreadsheet to table variable?
              TᴀW Adobe Community Professional & MVP

              On Windows, it would be like this:

               

                var vb;
                vb = "\rSet myExcel = CreateObject(\"Excel.Application\")";
                vb += "\rDim s";
                vb += "\rSet objWorkbook = myExcel.Workbooks.Open(/*Path to Excel Doc*/)";
                vb += "\rSet objSheet = myExcel.ActiveWorkbook.WorkSheets(1)";
                vb += "\rs = objSheet.Cells(1, 2).Text";
                vb += "\robjWorkBook.close";
                vb += "\rreturnValue = s";
                result = app.doScript (vb, ScriptLanguage.VISUAL_BASIC);
              
              

               

              This gives you the plain text of cell 1,2.

               

              Ariel