2 Replies Latest reply on Dec 29, 2015 9:01 AM by briank83163125

    content into a column in a selected table with existing content.

    briank83163125

      I wrote a simple script to add "." period to all the first column of my tables after the number.  I am bringing in data from excel that does not have a "." after the number. Here is the script:

       

      var myTable = app.activeDocument.stories.everyItem().tables.everyItem().getElements(); 

      var myColumns =  app.activeDocument.stories.everyItem().tables.everyItem().rows.everyItem().getElements();

       

      for(i=0; i<myTable.length; i++)

      for(t=0; t<myColumns.length; t++)

          myTable[i].columns[0].cells[t].contents += ".";

          } 

       

      This script works the way I want it to.  It adds a period after the content that is already in the cell.

       

      Here is my question, in case I have other tables in my document later that I do not want to add the "." to, how would I modify this script to apply it only to a selected table or column?

       

      I know there is "app.selection" but I'm not sure how to use it correctly.

       

      For a bonus, how do I undo the script all at once?  if I use the undo feature (ctrl z), it undoes one row at a time.  The reason I might need it is if i accidentally run the script twice, i end up with two periods.  I cand do a find/change but was wondering how to write a script that would fix the error.

       

      Thanks