Home > InDesign Scripts > Selecting multiple table rows/columns

Selecting multiple table rows/columns

Here is short script for selecting multiple rows in table. This will create ‘visible’ selection. This script is also published on Adobe’s InDesign scripting forum but I found some parts on other sites too.

First example shows how to select first 5 rows:

myTable = app.selection[0].tables[0];
myRows = 5;

for (var i = 0; i <= myRows - 1; i++){
    if (i==0){
        myTable.rows[i].select();
    }else{
        myTable.rows[i].select(SelectionOptions.ADD_TO);
    }
}

Now, we can copy selected rows with app.copy();, and then paste it in other text frame with app.paste();. If you want to clear selection after copying, you can do this:

app.selection = NothingEnum.NOTHING;

If we have for example header rows, we just alter line 2 to receive headerRowsCount:

myRows = myTable.headerRowCount;

And for the end, we can create function that selects rows based on our input of first row and number of rows that we want to select:

function rowSelecting(firstRow,rowCount){
    for (var i = 0; i <= rowCount-1; i++){
        if (i==0){
            myTable.rows[i+firstRow].select();
        }else{
            myTable.rows[i+firstRow].select(SelectionOptions.ADD_TO);
        }
    }
}

Usage:

var myTable = app.selection[0].tables[0];
rowSelecting(3,1);

If we want to do same, but with columns, we simply change myTable.rows with myTable.columns and that’s it. Have fun! :D

About these ads
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 34 other followers

%d bloggers like this: