Question
Script to Merge Duplicate Table Cells
Hello! I am trying to modify this script (which I can't seem to get to work).
It is intended to merge all consecutive duplicate cells:
//Merge Same-text Table Cells by Sunil Yadav
var myDocument = app.activeDocument;
var allTables = app.selection[0].parentStory.tables.everyItem().getElements();
for (var tf = 0; tf < app.selection.length; tf++) {
var mySelection = app.selection[0];
var myStory = mySelection.hasOwnProperty("storyOffset") ? mySelection.storyOffset.parentStory : mySelection.insertionPoints[0].parentStory;
Merge(mySel);
}
function Merge (mySel){
for( var j = 0; j< mySel.tables.length ; j++ ){
for (var f = 0; f < mySel.tables.columns.length; f++){
for( var i = 0; i< mySel.tables.columns.cells.length ;i++ ){
var a = mySel.tables.columns.cells.contents;
if(i < mySel.tables.columns.cells.length-1){
if(mySel.tables.columns.cells[i+1].contents==a){
mySel.tables.columns.cells.contents = "";
mySel.tables.columns.cells.merge(mySel.tables.columns.cells[i+1]);
mySel.tables.columns.cells.verticalJustification = 1667591796;
f = -1;
i = -1;
}
}
}
}
}
} Any pointers?
Initial:

After script:

