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!")}
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
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
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
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
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
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
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.
-Manan
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();
}
}
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
Copy link to clipboard
Copied
Thank you alot Manan,
I appreciate your help, thank you very much
Copy link to clipboard
Copied
Hi,
This is so helpful, thank you! Is there also a way to remove the character styles that may have been applied to text within a cell?