2 Replies Latest reply on Jun 16, 2013 5:32 AM by rajnikids

    Replace table row cell[1] text with cell[0]

    rajnikids Level 1

      Hi Forum,


      Thanks for your support so far. I have come up with new request, please anyone there to quench by thirst;


      actually i want to replace, cell[1] of the every rows of every table with cell[0] of every rows of every table.


      I dont think its a right way of doing this like i doing now;;


      myPage =app.activeDocument.pages.everyItem();

      var mytable =myPage.textFrames.everyItem().tables.everyItem().columns[0];




      Also, i tried in this way.... but script find only the first instance and replace... and not the next cell[1] with cell[0] on next row..


      myPage =app.activeDocument.pages.everyItem();

      var mytable =myPage.textFrames.everyItem().tables.everyItem();

      var c1 =mytable.rows.everyItem().cells[0].contents;

      var c2 = mytable.rows.everyItem().cells[1].contents;

      app.findTextPreferences = null;

      app.changeTextPreferences = null;

         app.findTextPreferences.findWhat =c1;

         app.changeTextPreferences.changeTo =c2;



      please help on this..

        • 1. Re: Replace table row cell[1] text with cell[0]
          Laubender Adobe Community Professional & MVP

          @rajnikids – do you mean you want to change the contents (=unformatted text) of every column[1] of every table to the corresponding contents of column[0] of the particular table? Does formatting of text matters?


          If not (formatting of text in all cells of the two columns is absolutely the same!), you could iterate through all stories of your document and through all tables of thiese stories and assign the contents of column[0] to the contents of column[1].


          The contents of a column is an Array of text strings.


          The following is only working, if the length of every cells in the two columns is the same (no merged cells!):


          var d=app.documents[0];
          var allTablesArray=d.stories.everyItem().tables.everyItem().getElements();
          for(var n=0;n<allTablesArray.length;n++){
              //Contents of column[0]:
              var c0 = allTablesArray[n].columns[0].contents;
              //Assign this contents to column[1]:
              allTablesArray[n].columns[1].contents = c0;


          If formatting is a problem, you could set the contents of column[1] to an empty string (= removing all contents of all cells of column[1]). Afterwards you have to iterate through all cells of column[0] and duplicate texts[0] to the first insertion point of the corresponding cell of column[1].



          • 2. Re: Replace table row cell[1] text with cell[0]
            rajnikids Level 1




            Superb and very technical approach of duplicating the columns contents.


            Very surprised to see your reply after a long time...


            thanks so much for your explanations, have litereated me how to do this....


            thanks thanks thanks.....