Skip to main content
June 3, 2013
Answered

Selecting last row of table

  • June 3, 2013
  • 2 replies
  • 997 views

I'm trying to select the last row in a table. The tables will have a different number of rows, so I cannot select based on a row number. I tried using the location options, but get an error that "The Object is not a function." Not sure what the problem is.

table = app.selection[0];

if (table.hasOwnProperty("baseline")) table = table.parent;

if (table instanceof Cell) table = table.parent;

if (table instanceof Column) table = table.parent;

if (table instanceof Row) table = table.parent;

if (table instanceof Table)

{

            table.rows(LocationOptions.AT_END).cells.texts.everyItem().fontStyle = "regular";

}

Can you use the location options for this?

This topic has been closed for replies.
Correct answer Jump_Over

Hi,

table.rows is a colection of object so  using [-1] index is a correct way

but cells.texts generates an error. Modify it to:

table.rows[-1].cells.everyItem().texts.everyItem().appliedCharacterStyle = "myriad regular";

Jarek

2 replies

Jump_Over
Jump_OverCorrect answer
Legend
June 3, 2013

Hi,

table.rows is a colection of object so  using [-1] index is a correct way

but cells.texts generates an error. Modify it to:

table.rows[-1].cells.everyItem().texts.everyItem().appliedCharacterStyle = "myriad regular";

Jarek

June 5, 2013

Yes, that worked -- thanks!

TᴀW
Legend
June 3, 2013

I'm not sure if it's such a good idea to use the string "table" as a

variable name. Things can get very confused that way (especially if you

happen to use an "with" statements)

Anyway, to select the last row of a table, this should work:

myTable.rows[-1].select();

HTH,

Ariel

id-extras.com | InDesign tools & scripts for typesetters, form designers, and translators
June 3, 2013

I'm new to scripting, and am not sure how the myTable function works or how to set it up.

So I tried adding this in:

table.rows[-1].select().cells.texts.everyItem().appliedCharacterStyle = "myriad regular";

but when I run the script, I get the error message "undefined is not an object."