How to Remove All Table / Cell Styles via Script or Delete Them

Engaged ,
Jun 09, 2021 Jun 09, 2021

Copy link to clipboard

Copied

Hi Experts,

I develped a Script that will remove all Table Styles but also i want to add Cell Styles to the Script? any help please, heres is my code :

 

//Remove All Table Styles
for (s=0; s<app.activeDocument.stories.length; s++)  
for (t=0; t<app.activeDocument.stories[s].tables.length; t++)
  try{
   app.activeDocument.stories[s].tables[t].appliedTableStyle.remove();
}
catch (e){alert ("All Tables Styles Removed!")}

 

 

Best
M.Hasanain
TOPICS
Scripting

Views

245

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct Answers

Adobe Community Professional , Jun 09, 2021 Jun 09, 2021
Try the following var ts = app.documents[0].stories.everyItem().tables.everyItem().appliedTableStyle for(var i = 0; i < ts.length; i++) try{ts[i].remove()}catch(e){} var cs = app.documents[0].stories.everyItem().tables.everyItem().cells.everyItem().appliedCellStyle for(var i = 0; i < cs.length; i++) try{cs[i].remove()}catch(e){} -Manan

Likes

Translate

Translate
Adobe Community Professional , Jun 10, 2021 Jun 10, 2021
Try the following then var ts = app.documents[0].tableStyles.everyItem().getElements() for(var i = 0; i < ts.length; i++) try{ts[i].remove()}catch(e){} var cs = app.documents[0].cellStyles.everyItem().getElements() for(var i = 0; i < cs.length; i++) try{cs[i].remove()}catch(e){} -Manan

Likes

Translate

Translate
Adobe Community Professional ,
Jun 09, 2021 Jun 09, 2021

Copy link to clipboard

Copied

Try the following

var ts = app.documents[0].stories.everyItem().tables.everyItem().appliedTableStyle
for(var i = 0; i < ts.length; i++)
	try{ts[i].remove()}catch(e){}
	
var cs = app.documents[0].stories.everyItem().tables.everyItem().cells.everyItem().appliedCellStyle
for(var i = 0; i < cs.length; i++)
	try{cs[i].remove()}catch(e){}

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 09, 2021 Jun 09, 2021

Copy link to clipboard

Copied

Thank You a lot for your reply , but the table styles only removed and still cell styles as is not removed

Best
M.Hasanain

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 09, 2021 Jun 09, 2021

Copy link to clipboard

Copied

Should work. Did you try debugging on where it fails? Provide a sample document if you can't figure out the issue.

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 09, 2021 Jun 09, 2021

Copy link to clipboard

Copied

Hi, Here is the Link of the Project :

https://drive.google.com/drive/folders/1es4d4B3QGo6fxTNxxDfwEQ59y4r3BM7w?usp=sharing 

i notice that the table styles deleted but the cell style not deleted, im using indesign 2021 - 16.2.1-x64 - Windows 10 Pro X64

Best
M.Hasanain

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 09, 2021 Jun 09, 2021

Copy link to clipboard

Copied

The cell styles is not deleted because those styles are not applied to any cell in the tables. All the cells have [None] cell style applied which can't be deleted.

Looking at your question heading and also the alert you wrote in the catch you seem to point towards deleting all table and cell styles. However, your code snippet deletes only the applied table styles and that is what I extended to delete applied cell styles. Deleting all the styles does not make much sense to me after all due to the following reasons.

  • Why do you need a script for it. You can select all the styles in the panel and delete them in one go. An easy and faster way to clean if it's needed
  • What purpose would deleting unused(not applied) style serve?

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

Hi, thank you for your reply again, actually we need to remove all styles (characte styls - paragraph styles - object styles ) i already succeded in making script for those but not success in table and cell styles, they need special treatment!, our company deliver project files to press and want to avoid changing anythings by get rid from all styles,  i also tried the below script (but now working! and no errors!) :

 

 myDoc = app.activeDocument; 
 //Remove All Table Styles
    var Tabls1 = myDoc.tableStyles.length;
      for(var j=Tabls1-1; j>0; j--) //j++ replaced here by j--    
    {    
      var TableRes = myDoc.tableStyles[j].remove();    
    }
}

 

 

Best
M.Hasanain

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

Try the following then

var ts = app.documents[0].tableStyles.everyItem().getElements()
for(var i = 0; i < ts.length; i++)
	try{ts[i].remove()}catch(e){}
	
var cs = app.documents[0].cellStyles.everyItem().getElements()
for(var i = 0; i < cs.length; i++)
	try{cs[i].remove()}catch(e){}

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 10, 2021 Jun 10, 2021

Copy link to clipboard

Copied

LATEST

Thank you alot Manan,  

I appreciate your help, thank you very much

Best
M.Hasanain

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines