Copy link to clipboard
Copied
Dear experts,
is there any way (a Script?) to format all tables in my project as I formatted the first one? In all tables: the first column has to be 56 mm wide, the second 13 mm, and the third 56 mm. Tables have from three to seven rows and the last row needs to be formatted with the "tab. bottom" Cell Style; other rows with "tab." Cell Style. Everything else is formatted as it should be.
Of course, I can do it one by one but there are over 1000 tables... Any ideas?
MJ
Having a merged footer row complicates matters but something like this might work. Seemed to work on your sample but not sure what other pitfalls exists on your full document.
var tables = app.activeDocument.stories.everyItem().tables.everyItem();
tables.rows.lastItem().unmerge();
tables.columns[0].width = "56 mm";
tables.columns[1].width = "13 mm";
tables.columns[2].width = "56 mm";
tables.cells.everyItem().applyCellStyle(app.activeDocument.cellStyles.itemByName("tab."), true);
tables.rows
...
Copy link to clipboard
Copied
Having a merged footer row complicates matters but something like this might work. Seemed to work on your sample but not sure what other pitfalls exists on your full document.
var tables = app.activeDocument.stories.everyItem().tables.everyItem();
tables.rows.lastItem().unmerge();
tables.columns[0].width = "56 mm";
tables.columns[1].width = "13 mm";
tables.columns[2].width = "56 mm";
tables.cells.everyItem().applyCellStyle(app.activeDocument.cellStyles.itemByName("tab."), true);
tables.rows.lastItem().cells.everyItem().applyCellStyle(app.activeDocument.cellStyles.itemByName("tab. bottom"), true);
tables.rows.lastItem().merge();
Copy link to clipboard
Copied
Thank you very much! That works almost perfectly. Now I have good Celle Styles applied, but all are with +:
I can't find the right English name but now I have to hold left Alt and click on "tab." Cell Style to make all cells with my settings. Is there any way to run a second script that removes all overrides (those pluses) from applied styles?
Copy link to clipboard
Copied
app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().clearCellStyleOverrides(true);
Copy link to clipboard
Copied
This is weird. This removes all formatting from tables:
But when I choose Clear Overrides from the Cell Styles menu everything is as it should be.
Copy link to clipboard
Copied
Any ideas on how to solve that problem?
Copy link to clipboard
Copied
I've changed "true" to "false" and now it is working as expected:
app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().clearCellStyleOverrides(false);