Skip to main content
December 16, 2017
Answered

Looking for a script to add one row at the end of a table, merge it and add text

  • December 16, 2017
  • 1 reply
  • 2833 views

Hi all,

My client decided they want to add a row at the end of all the tables with a note. I figured out how to add the row using the script below, but cannot figure out how to merge that row and then add in the new copy. Currently the tables are one row, three columns. The new row should be merged across all the columns (see example below). Can anyone tell me if this is even possible to script? I have tons of documents I have to do this on so any help would be greatly appreciated!

var curDoc = app.activeDocument;

var allTables = curDoc.stories.everyItem().tables.everyItem().getElements();

for ( var t = 0; t < allTables.length; t++ ) {

    var curTable = allTables;

    var allRows = curTable.rows;

curTable.rows.add(LocationOptions.AT_END);

}

This topic has been closed for replies.
Correct answer lfcorullon13651490

I'm not on my PC now, but I would try something like:

var curDoc = app.activeDocument;

var allTables = curDoc.stories.everyItem().tables.everyItem().getElements();

for ( var t = 0; t < allTables.length; t++ ) {

var curTable = allTables;

var allRows = curTable.rows;

var newRow = curTable.rows.add(LocationOptions.AT_END);

newRow.cells.everyItem().merge();

}

>

1 reply

lfcorullon13651490
lfcorullon13651490Correct answer
Legend
December 16, 2017

I'm not on my PC now, but I would try something like:

var curDoc = app.activeDocument;

var allTables = curDoc.stories.everyItem().tables.everyItem().getElements();

for ( var t = 0; t < allTables.length; t++ ) {

var curTable = allTables;

var allRows = curTable.rows;

var newRow = curTable.rows.add(LocationOptions.AT_END);

newRow.cells.everyItem().merge();

}

>

Obi-wan Kenobi
Legend
December 16, 2017

Corullon,

Next time, turn on your machine! …

newRow.cells[0].merge (newRow.cells[-1]);

(^/)

December 16, 2017

That worked, thank you both! Is there a way to add this copy to that row as well?

Note: If the student responds incorrectly, proceed to the next set of DO and SAY statements below.