1 Reply Latest reply on Jun 26, 2014 11:36 PM by Chinnadk

    Copy content from table cell of one document in InDesign to text frame of a different document in InDesign

    malhar1991

      var newdoc;                                      //Creates a new document that will have a text frame

      newdoc = app.documents.add(false);

      with (newdoc.documentPreferences) {

          pageHeight = "825pt";

          pageWidth = "637pt";

          pageOrientation = PageOrientation.PORTRAIT;

          pagesPerDocument = 1;

          //setting bleed properties for the document

          documentBleedUniformSize = true;

          documentBleedTopOffset = "9pt";

          //setting slug properties for the document

          documentSlugUniformSize = true;

          slugTopOffset = "0pt";

      }

       

      var doc = app.activeDocument,          // Opens current or active document which has a table

          _tables = doc.stories.everyItem().textStyleRanges.everyItem().getElements(),     

          i, j, k, l, a, _rows, _cells, rowlen, tempVar, page;

       

      page = newdoc.pages.items[0];

       

      var TextFrame = page.textFrames.add();           //Creates TextFrame

      TextFrame.geometricBounds = myGetBounds(doc, page);

       

      for (i = 0; i < _tables.length; i++) {

          for (j = 0; j < _tables[i].tables.length; j++) {

              _rows = _tables[i].tables[j].rows;

              for (k = 0; k < _rows.length; k++) {

                  _cells = _rows[k].cells;

                  for (l = 0; l < _cells.length; l++) {

                     

                      tempVar = _cells[0].contents;          //Copy contents from table cell to a temporary variable

                      TextFrame.contents = tempVar;        //write it into text frame.

       

       

                  }

              }

          }

      }

       

      The bold text is where error "undefined is not an object" is shown. Please help with the code. I am new to Indesign scripting.

        • 1. Re: Copy content from table cell of one document in InDesign to text frame of a different document in InDesign
          Chinnadk Level 4

          Hi,

           

          Try this.

           

          var doc = app.activeDocument,          // Opens current or active document which has a table
              _tables = doc.stories.everyItem().textStyleRanges.everyItem().getElements(),   
              i, j, k, l, _rows, _cells, tempVar = "", page;
             
          for (i = 0; i < _tables.length; i++)
          {
              for (j = 0; j < _tables[i].tables.length; j++)
              {
                  tempVar += "\r";
                  _rows = _tables[i].tables[j].rows;
                  for (k = 0; k < _rows.length; k++)
                  {
                      _cells = _rows[k].cells;
                      tempVar += "\r";
                      for (l = 0; l < _cells.length; l++)
                      {
                          tempVar += _cells[l].contents + "\t";          //Copy contents from table cell to a temporary variable
                      }
                  }
              }
          }   
             
          var newdoc = app.documents.add();
          with (newdoc.documentPreferences) {
              pageHeight = "825pt";
              pageWidth = "637pt";
              pageOrientation = PageOrientation.PORTRAIT;
              pagesPerDocument = 1;
              //setting bleed properties for the document
              documentBleedUniformSize = true;
              documentBleedTopOffset = "9pt";
              //setting slug properties for the document
              documentSlugUniformSize = true;
              slugTopOffset = "0pt";
          }
          
          page = newdoc.pages[0];
          var _TextFrame = page.textFrames.add();          //Creates TextFrame
          _TextFrame.geometricBounds = newdoc.pages[0].bounds;
          _TextFrame.contents = tempVar;
          

           

          Regards,

          Chinna