Reply To: Looping Through InDesign Table for Specific String

#90646
Anonymous
Inactive

May I suggest this approach ?

var main = function() {
var doc = app.properties.activeDocument, myTable, cells, strings, cell;
if ( !doc || app.selection.length != 1 || !(app.selection[0] instanceof Table )) {
alert(“You need to select a table to get this script up and running”);
return;
}

strings = {
//Property name = expected cell content
//Property value stands for the new string value
“Air Conditioning & Heating” : “Heating & Air Conditioning”,
“Basement Remodeling & Additions” : “Home Additions & Basement Remodeling”,
//Etc.
}

myTable= app.selection[0];
cells = myTable.cells.everyItem().getElements();
while ( cell = cells.shift() ) {
if ( strings[cell.contents] ) {
myTable.rows.add().cells[0].contents =”###” + strings[cell.contents];
}
}
}

var u;

app.doScript ( “main()”,u,u,UndoModes.ENTIRE_SCRIPT, “The Script” );

Otherwise if the table is filled with strings only without any special characters nor anchored objects, you may have take advantage of the myTable.contents property which returns an array of strings. Then you could have looped through this array, do changes and fill this array back into the table. Much much quicker ;)

This article was last modified on December 20, 2016

Comments (0)

Loading comments...