Automatically Style Tables depending on their table style
Hi,
I have some very large documents with hundreds of tables, with two different table styles allocated (ie, some tables have "Table Style One" and some have "Table Style Two"). My issue is, whilst I have the two different table styles correctly assigned as required, I need to add much more complex cell styles to make them appear as I would like (see required look of tables attached at the bottom of this message).
Via Javascript/Extend Script, I would like to be able to 1) Target all tables in active document and clear Cell Style Overrides 2) 'Loop' through the active document and 'If' the table has "Table Style One" applied, then apply certain cell styles to the first row, second row, last row, second-to-last row and third-to-last row, 'Or' 'If' the table has "Table Style One" applied, the apply certain cell styles to the first row, the first column (excluding the first row), the last column (excluding the first row), the second-to-last column (excluding the first row) and third-to-last column (excluding the first row).
Here's where I am so far (it clears the cell style overrides ok, but that's all I've got so far, it's a work-in-progress!)...
Any help at all would be GREATLY appreciated.
Thanks ![]()
// This script assumes an Indesign Document is active (open), clears Cell Style Overrides in the active document, then if the table has a table style of "TableStyleOne", applies certain cells styles to its rows and columns, if the table has a table style of "TableStyleTwo", then it applies different cell styles to its rows and columns.
var allStories = app.activeDocument.stories.everyItem();
// Remove overrides from all cells
try {
allStories.tables.everyItem().cells.everyItem().clearCellStyleOverrides(true);
}
// If no tables exist, display alert box "No table exist!"
catch (err) {
alert ("No tables exist!");
}
// Once overrides have been cleared, display alert box "Cell Style Overrrides have been cleared!"
alert ("Cell Style Overrrides have been cleared!");
// Declare (define) variables for the two different table
var myTableStyleOne = allStories.tables.everyItem().; // THIS ISN'T FINISHED!!!
var myTableStyleTwo = allStories.tables.everyItem().; // THIS ISN'T FINISHED!!!
// Create the if/else statements (If this is true, do this, if not, do this instead)

