2 Replies Latest reply on Dec 7, 2015 8:33 AM by graemem34292562

    Merge table cells based on paragraph style




      I am new to InDesign scripting and have been searching the forum for script to merge table cells based on a paragraph style.


      I am using tables to import xml data into an Indesign document, which will be approx 250 pages. In the xml I am using "aid:pstyle" xml attributes to catch paragraph styling on the xml import as well as some cell styling to format tables. However, in some instances I want to use a script merge table cells horizontally create a 2 column row. The 2nd column on each row  to be merged has a paragraph style "tableBodyMere" and I am looking for a small javaScript solution to:


      1, Look at all tables in the document and find the paragraph style "tableBodyMerge" The table is 6 columns wide and  "tableBodyMerge" is always assigned to text on column 2 of each row.

      2, When "tableBodyMerge" is found conduct a cell merge from 6 columns to 2, starting from column 2. So the row ends up as a 2 column row.



      Screen Shot 2015-12-07 at 12.15.34.png


      Screen Shot 2015-12-07 at 12.21.45.png


      Any assistance would be much appreciated

        • 1. Re: Merge table cells based on paragraph style
          Jump_Over Level 5



          A raw solution could be like this:

            mColumns = app.activeDocument.stories.everyItem().tables.everyItem().columns[1].getElements(),
            cColumn, cCells, cCell;
            targetStyle = app.activeDocument.paragraphStyles.item("tableBodyMerge");
            while (cColumn = mColumns.shift()) {
                 cCells = cColumn.cells.everyItem().getElements();
                 while (cCell = cCells.shift()) {
                      if (cCell.insertionPoints[0].appliedParagraphStyle == targetStyle)


          Still open problem for above code:

               - what to do if further cell's contents exists (now merge anyway)



          • 2. Re: Merge table cells based on paragraph style
            graemem34292562 Level 1

            Hello - your solution worked a treat!


            One enhancement would once completed rename merged "tableBodyMerge" rows to "TableBody"