Skip to main content
Inspiring
February 13, 2023
Question

find tables and apply table-style to all

  • February 13, 2023
  • 3 replies
  • 945 views

Dear all! Is there a possibility to find all tables (all table-text has a special paragraph-style "TableText") and apply tablestyle to all in 1 go? thank you thank you thank you 🙂

This topic has been closed for replies.

3 replies

Peter Kahrel
Community Expert
Community Expert
February 13, 2023

The name of the table style should be changed in the script;

style = app.documents[0].tableStyles.item('My_Table');
tables = app.documents[0].stories.everyItem().tables.everyItem().getElements();
for (i = 0; i < tables.length; i++) {
  if (tables[i].storyOffset.appliedParagraphStyle.name == 'TableText') {
    tables[i].appliedTableStyle = style;
  }
}
Inspiring
February 13, 2023

Yes, I did that but still got the error...

 

Peter Kahrel
Community Expert
Community Expert
February 13, 2023

Could you send your document to pkahrel@gmail.com?

Peter Kahrel
Community Expert
Community Expert
February 13, 2023

Sorry, Caroline, I should have read your post more carefully. The tables you're after are in a paragraph style TableText, and you want to apply a table style. You didn't say what the name of the table style is, in the updated script, below, I assumed TableText (same name as the paragraph style). If you use a different name, replace TableText in the script's first line with the name you use.

style = app.documents[0].tableStyles.item('TableText');
tables = app.documents[0].stories.everyItem().tables.everyItem().getElements();
for (i = 0; i < tables.length; i++) {
  if (tables[i].storyOffset.appliedParagraphStyle.name == 'TableText') {
    tables[i].appliedTableStyle = style;
  }
}

 

Inspiring
February 13, 2023

Oh dear, it seems I make a mistake again. My Table-style is named My_Table, my paragraph-style TableText. But still i get an error.Complicated matter these scripts... Thanks for your time and patience!

Peter Kahrel
Community Expert
Community Expert
February 13, 2023

It'll have to be a script:

 

style = app.documents[0].tableStyles.item('TableText');
tables = app.documents[0].stories.everyItem().tables.everyItem().getElements();
for (i = 0; i < tables.length; i++) {
  tables[i].appliedTableStyle = style;
}

P

Inspiring
February 13, 2023

Dear Peter, that looks promiing but unfortunately I get an error: