2

I have an InDesign CC 2018 document which I imported a docx file. The file contains a lot of tables. I want to apply a table style to all of the tables, but we are talking hundreds of tables.

Is there a script that will select tables and apply a specific style?

Or is there a way to apply table styles to all tables in a document at once?

Thanks in advance

3

Ok, I think I can answer my own question, and leave it as a reference for others who might be looking for a solution.

To apply a Table Style and Clear All Table Style and Cell Style Overrides on all tables within a document use this script:

for (s=0; s<app.activeDocument.stories.length; s++)  
for (t=0; t<app.activeDocument.stories[s].tables.length; t++)  
{  
     app.activeDocument.stories[s].tables[t].appliedTableStyle = "TableStyleNameGoesHere";  
     app.activeDocument.stories[s].tables[t].clearTableStyleOverrides();
}  

// Clear All Overrides

var allStories = app.activeDocument.stories.everyItem();

// Remove overrides from all footnotes
try{
   allStories.footnotes.everyItem().texts.everyItem().clearOverrides(myOverrideType);
}
catch (e){alert ("No footnotes!")}

// Remove overrides from all table
try{
   allStories.tables.everyItem().cells.everyItem().paragraphs.everyItem().clearOverrides(myOverrideType);
}
catch (e){alert ("No tables!")}

// Remove overrides from all cells
try{
allStories.tables.everyItem().cells.everyItem().clearCellStyleOverrides(true);
}
catch (e){alert ("No tables!")}

alert("Overrides cleared!"); 

This worked for me. Hopefully it will work for you.

1
  • allStories.footnotes.everyItem().texts.everyItem().clearOverrides(myOverrideType); What is myOverridesType? Mar 13 '20 at 10:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.