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 myParas = myTable.cells.everyItem().texts[0].paragraphs.everyItem().getElements(),
P = myParas.length,
myTextInCell = [“Activity”, “Possible Answers”],
myParaStyle = “table H2”,
myRegEx = new RegExp(“b(” + myTextInCell.join(“|”) + “)b”);
for ( var p = 0; p < P; p++) if (myParas[p].contents.match(myRegEx)) myParas[p].appliedParagraphStyle = myParaStyle;
}
//__(^/)