Copy link to clipboard
Copied
Hi Guys,
I need to create a new row with merge cell and apply footer row style
Plaese help.
var table = app.selection[0].parentStory.tables[0] ;
var newRow= table.rows.add( LocationOptions.AT_END).bottomEdgeStrokeWeight = 0;
var l=(table.rows.length)-1;
newRow.table.rows[l].cells.merge(table.rows[l].cells[0]);
Copy link to clipboard
Copied
Hi arunbitbtech, here's some help:
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Add Table Footer");
function main() {
if (app.selection.length == 0) {
alert('Please make a selection and run script again.');
} else if (!app.selection[0].parentStory.tables[0].isValid) {
alert('No table found in selection.');
} else {
var table = app.selection[0].parentStory.tables[0];
// add new row
var newRow = table.rows.add(LocationOptions.AT_END);
newRow.bottomEdgeStrokeWeight = 0;
// convert to footer row
newRow.rowType = RowTypes.FOOTER_ROW;
// merge all cells
newRow.getElements()[0].merge();
// set cell style of row's first cell
setCellStyle(app.activeDocument, newRow.cells.item(0), 'My footer cell style');
}
function setCellStyle(doc, _cells, styleName) {
// check if cell style exists before applying it
if (doc.cellStyles.itemByName(styleName).isValid) {
_cells.appliedCellStyle = doc.cellStyles.itemByName(styleName);
_cells.clearCellStyleOverrides(true);
} else {
alert('Cell Style "' + styleName + '" not found.');
}
}
}
Copy link to clipboard
Copied
The problem is that
var newRow = table.rows.add( LocationOptions.AT_END).bottomEdgeStrokeWeight = 0;
does not return a row, but 0. You should do it as in m1b's example: add a row, then set its various properties.