Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
7

Get all tables with a particular Table Style applied

Community Expert ,
May 20, 2024 May 20, 2024

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.
    }
}

 

TOPICS
Scripting
3.6K
Translate
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 1 Correct answer

Community Expert , May 20, 2024 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.leng
...
Translate
Community Expert ,
May 20, 2024 May 20, 2024
LATEST

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")
Translate
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