简体   繁体   中英

Adapting merge cells in InDesign script

I found this script on SO, which is very close to what I need. But instead of it merging the cells with the one above I need it to merge with the cell to left of any empty cell.

I have tried to experiment with it and manged to get it to merge horizontally once but it merge three cells that weren't empty into one.

Would be greatful for any help

THanks

var myDoc = app.activeDocument;

myPage = myDoc.pages;

for (var p=0; myPage.length>p; p++){

    try{

var myTable = myPage[p].textFrames.everyItem().tables.everyItem();

if (myTable.constructor.name == 'Table'){

for (var t = myTable.cells.length - 1; t >= 0; t--)
            {

           if (myTable.cells[t].contents==""){
              var w = myTable.columns.length;
               myTable.cells[t-w].merge(myTable.cells[t]);

               }

            }

        }

    }

  catch(e){}

}

I found a solution

 var i, j, cells;
// Get all the rows in the document
var rows = app.documents[0].stories.everyItem().tables.everyItem().rows.everyItem().getElements();
for (i = 0; i < rows.length; i++) {
    // Get all the cells in a row
    cells = rows[i].cells.everyItem().getElements();
    for (j = cells.length-1; j >= 1; j--) {
        if (cells[j].contents == '') {
            cells[j-1].merge (cells[j]);
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM