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

[CS3 JS]Get all the tables in the document

Community Expert ,
Nov 18, 2008 Nov 18, 2008
Hello All,

I want to return all of the tables in the document, including those in table cells. I am using this:

var aTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();

but it doesn't get tables inside of tables. Is there an easy way to do this without checking each table cell? Thanks in advance.

Rick Quatro
585-659-8267
TOPICS
Scripting
838
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
Community Beginner ,
Nov 18, 2008 Nov 18, 2008
I'm not JS man ... but maybe this will work:

var aTables = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().tables.everyItem().getElements();

robin

--
www.adobescripts.com
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
Participant ,
Nov 18, 2008 Nov 18, 2008
Rick,

There's no easy way to get all the tables in cells of tables. Given that they could be nested to any depth, a recursive search is necessary for a completely general solution.

Dave
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
Participant ,
Nov 18, 2008 Nov 18, 2008
Robin,

Your solution might work (I wondered about that), but you'd have to concatenate that array with the original one to get the lot, and it only goes down one level -- which in all probability, is enough.

Dave
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
Community Expert ,
Nov 18, 2008 Nov 18, 2008
Hi Robin and Dave,

Thanks for your replies. This seems to work fine.

var oDocTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
if (oDocTables.length)
oDocTables = GetAllTables(oDocTables);

alert(oDocTables.length);

function GetAllTables(oTables)
{
for(var i=0; i < oTables.length; i++)
{
var oCells = oTables.cells;
for (var j=0; j < oCells.length; j++)
{
var oCellTables = oCells.tables.everyItem().getElements();
if (oCellTables.length)
{
oTables = oTables.concat(oCellTables);
}
}
}
return oTables;
}
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
Community Expert ,
Nov 18, 2008 Nov 18, 2008
Hi Robin and Dave,

Thanks for your replies. This seems to work fine regardless of the nexting level.

Rick


var oDocTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
if (oDocTables.length)
oDocTables = GetAllTables(oDocTables);

alert(oDocTables.length);

function GetAllTables(oTables)
{
for(var i=0; i < oTables.length; i++)
{
var oCells = oTables.cells;
for (var j=0; j < oCells.length; j++)
{
var oCellTables = oCells.tables.everyItem().getElements();
if (oCellTables.length)
{
oTables = oTables.concat(oCellTables);
}
}
}
return oTables;
}
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
Explorer ,
Jan 21, 2009 Jan 21, 2009
Hi Rick,

Your script is working fine. But it gives only the table count. We have InDesignCS2 document and it have 100 nos of inline tables. I want to apply cell stroke, cell spacing and paragraph Style to the tables. If it is possible means, Could you please help me for this.

Thanks in advance
Thiyagu
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
Explorer ,
Jan 28, 2009 Jan 28, 2009
Hi Rick,

Can you help me for the above issue...?

Regards
Thiyagu
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
Explorer ,
Jan 28, 2009 Jan 28, 2009
LATEST
Hi Rick,

Your script is working fine. But it gives only the table count. We have InDesignCS2 document and it have 100 nos of inline tables. I want to find each and every tables to apply cell stroke, cell spacing and paragraph Style to those tables. If it is possible means, Could you please help me for this.

Thanks in advance
Thiyagu
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