Hi,
I am trying to create a script that will convert the last row of a table to a footer row (defined in a cell style within a table style) and do this once per text frame (throughout the entire document) and also add a header row once per page, to the first table on that page, again throughout the entire document.
Here is my script so far:
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 (aTable=0; aTable<allTables.length; aTable++)
{
processTable (allTables[aTable]);
}
} else
{
processTable (a_table);
}
}
function processTable(table)
{
// do something here!
table.breakFooters = HeaderFooterBreakTypes.ONCE_PER_TEXT_FRAME;
}
function checkWhichTable()
{
// ensure the user made a selection
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))
{
// No table selected
return null;
}
return currentTable;
}
This was taken from: https://creativepro.com/tackling-tables-through-scripting.php and seems to work. The bit I am struggling with is what to put after //do something here!
If I run this script as it is in InDesign it adds an override to every table with the style applied (I only have one style for this document) but makes no visual change to the table.
Any help would be much appreciated! I don’t expect anyone to go ahead and spend ages writing JavaScript for me but any pointers in the right direction would be great.
Thanks!