Skip to main content
frameexpert
Community Expert
Community Expert
May 20, 2024
Answered

Get all tables with a particular Table Style applied

  • May 20, 2024
  • 1 reply
  • 3644 views

I want to process all tables in my InDesign document that have the "summary.product" Table Style applied. Currently, I am using the code below, which gets all of the table and then checks each with a loop. But I am wondering if there is a way to get them with a single line.

var tables, count, i;
    
tables = app.activeDocument.stories.everyItem ().tables.everyItem ().getElements ();
count = tables.length;
for (i = 0; i < count; i += 1) {
    if (tables[i].appliedTableStyle.name === "summary.product") {
        // Process the table.
    }
}

 

This topic has been closed for replies.
Correct answer rob day

Hi @frameexpert , I don’t think so—if there is a conditional you have use some kind of loop.

 

If you wanted to change the properties all of the tables in a document you can do something like this:

 

var tables = app.activeDocument.stories.everyItem ().tables.everyItem ().properties = {appliedTableStyle = "summary.product"};

 

You could shorten the code with a while statement—something like this:

 

var t = app.activeDocument.stories.everyItem ().tables.everyItem ().getElements ();
var i = t.length; while (i--) if (t[i].appliedTableStyle.name === "summary.product") alert("Do Something")

1 reply

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
May 20, 2024

Hi @frameexpert , I don’t think so—if there is a conditional you have use some kind of loop.

 

If you wanted to change the properties all of the tables in a document you can do something like this:

 

var tables = app.activeDocument.stories.everyItem ().tables.everyItem ().properties = {appliedTableStyle = "summary.product"};

 

You could shorten the code with a while statement—something like this:

 

var t = app.activeDocument.stories.everyItem ().tables.everyItem ().getElements ();
var i = t.length; while (i--) if (t[i].appliedTableStyle.name === "summary.product") alert("Do Something")