Skip to main content
Participant
April 14, 2021
Answered

Script to fix Cell style overrides in a table

  • April 14, 2021
  • 1 reply
  • 1080 views

Hello,

 

I'm looking for a script that allows me to correct cell style overrides in a table.
I found one but it is not restrictive enough, I would like it to fix all the replacements except when the style "without" is associated with the cell.

Thank you in advance.

Correct answer Sunil Yadav

You may try this below code:

 

if(app.documents[0].stories.everyItem().tables.everyItem().length > 0){
    var cells = app.documents[0].stories.everyItem().tables.everyItem().cells.everyItem().getElements();
    for(var i = 0; i < cells.length; i++){
        if(cells[i].appliedCellStyle.name.toLowerCase() != "without"){
            cells[i].clearOverrides (true);
            }
        }
    }

 

Best

Sunil

1 reply

Diren16B8Author
Participant
April 14, 2021

here is the script I am currently using:

 

// Clear All Overrides
// Written by TAW. (c) 2014 by Bookraft Solutions, Israel (Id-Extras.com)
// Please do not delete this copyright notice.
//

var myOverrideType = OverrideType.ALL;
// var myOverrideType = OverrideType.CHARACTER_ONLY;
// var myOverrideType = OverrideType.PARAGRAPH_ONLY;

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

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

// 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!")}

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

Sunil Yadav
Legend
April 16, 2021

So you want to clear overrides only withing Cell?

Or only outside of cell?

 

Best

Sunil

Sunil Yadav
Sunil YadavCorrect answer
Legend
April 16, 2021

You may try this below code:

 

if(app.documents[0].stories.everyItem().tables.everyItem().length > 0){
    var cells = app.documents[0].stories.everyItem().tables.everyItem().cells.everyItem().getElements();
    for(var i = 0; i < cells.length; i++){
        if(cells[i].appliedCellStyle.name.toLowerCase() != "without"){
            cells[i].clearOverrides (true);
            }
        }
    }

 

Best

Sunil