18 Replies Latest reply on May 30, 2017 11:31 PM by Cleo_helm

    Adding parts of a Excel file into an InDesign text frame

    Cleo_helm

      Hello,

      I'm new to JavaScript in InDesign and try to code some things to understand it. I use CS6 (Version 8.0).

      I can place an Text or Excel file into an InDesign document, that is not an issue. But now I want to place single cells of an Excel table into the InDesign document in separate text frames.

       

      First one question: function xy() means that JavaScript should run this function (the paranthese) and in the curly brackets say how to do the function: function xy(){}, correct?!

       

      At the moment the result is just my Title Textframe on top and the whole Excel table.

       

      How can define in the place method that I want a specific part of my EXCEL file only?

       

      my Code:

          //Define the file I want to use

      var myList = new File("H:/test-excel.xlsx");

         //If NOT the indicated Excel-file exist do the following

      if(!myList.exists) {

                 alert("Save the Excel file");

              }

        //If the indicated Excel-file exist do the following stuff in the else{}

        else {     

                  //open a new document     

               var myDocument = app.documents.add();    

                      //use this current page

              var myPage = myDocument.pages.item(0);

                       //Now we tell the script which measurement units we take, in this case points (pt)

              myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;

              myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;

         

                      //defines the Title text frame including content and style

               var myTextFrameTitle = myDocument.textFrames.add();

                      //defines the size of the text frame [y1, x1, y2, x2], which give the coordinates of the top-left and bottom-right corners of the textframe

                      myTextFrameTitle.geometricBounds = [36,36,55,300];

                               //what to write in the field

                      myTextFrameTitle.contents = "Titel";

                              //which font and size

                      myTextFrameTitle.paragraphs.firstItem().appliedFont = app.fonts.item("Arial");

                      myTextFrameTitle.paragraphs.firstItem().fontStyle = "Bold";

                      myTextFrameTitle.paragraphs.firstItem().pointSize= 16;

                      myTextFrameTitle.paragraphs.firstItem().justification = Justification.LEFT_ALIGN

       

                      //adds the text of only the first Excel sheet to the document below the Title text frame

              var myExcelRowA = myDocument.textFrames.add();

                           //here are all Excel frames which are upcoming defined           

                     myExcelRowA.geometricBounds =[65, 36, 90, 68];

                             //place the Excel file into the text field

                     myExcelRowA.place(myList, undefined, false, true)[0];

       

      I know that I define my Excel file like this, but I don't get this two together:

      //starts a function (named "myImport") to import specific parts of an Excel file

              function myImport(){

                           //says how the Excel file should be imported

                          with (app.excelImportPreferences) {

                                   alignmentStyle = [AlignmentStyleOptions.SPREADSHEET][0];                          

                                   sheetIndex = 1;

                                   sheetName = "Institute"; //name of the sheet

                                   rangeName = "A1:B2"; //from first to last cell

                                   showHiddenCells = false; //doesn't show hidden cells, write true to also show hidden cells

                                   tableFormatting = TableFormattingOptions.Excel_Formatted_Table;

                                   //viewName = "H:/2017_05_01_HMGU-Struktur_verbesserungen/scripts/test-excel.xlsx";

                                   //myExcel content will appear on the page which is taken form the Excel document

                                  } //closing of with

                } //closing of function