Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Dec 28, 2015 Dec 28, 2015

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.columns[0].cells.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

TOPICS
Scripting
281
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 29, 2015 Dec 29, 2015
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 29, 2015 Dec 29, 2015
LATEST

This is the Code I ended up with from reading on this site https://indesignsecrets.com/tackling-tables-through-scripting.php


var myTable = app.selection[0].tables.everyItem().getElements();

var myColumns =  app.selection[0].tables.everyItem().rows.everyItem().getElements();

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

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

{

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

    }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines