Reply To: Script to apply paragraph style to text found in table cell

#93701

function checkWhichTable()
{
if (app.selection.length != 1) return null;
var currentTable = app.selection[0];
if (currentTable.hasOwnProperty(“baseline”)) currentTable = app.selection[0].parent;
while (currentTable instanceof Cell || currentTable instanceof Row || currentTable instanceof Column) currentTable = currentTable.parent;
if (!(currentTable instanceof Table)) return null;
return currentTable;
}

app.doScript(checkUserSelection, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, “Process Table”);

function checkUserSelection ()
{
var a_table = checkWhichTable();
if (a_table == null) {
if (confirm(“No table selected. Do you want to process *all* tables?”) == false)
return;
allTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
for (var a = 0; a < allTables.length; a++) processTable (allTables[a]);
} else processTable (a_table);
}

function processTable(myTable)
{
myTable.rows.everyItem().height = “36pt”;
myTable.cells.everyItem().autoGrow = true;
var myCells = myTable.cells.everyItem().getElements(),
C = myCells.length,
myTextInCell = [“Activity”, “Possible Answers”],
myRegEx = new RegExp(“b(” + myTextInCell.join(“|”) + “)b”);
for ( var c = 0; c < C; c++) if (myCells[c].texts[0].contents.match(myRegEx)) myCells[c].texts[0].paragraphs[0].appliedParagraphStyle = “table H2”;
}

//__(^/)

This article was last modified on April 13, 2017

Comments (0)

Loading comments...