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!
IndiSnip on Twitter!
IndiSnip on Facebook!
Contact IndiSnip by e-mail!
