4 Replies Latest reply on Oct 29, 2012 1:48 PM by KuddRoww

    Merging cells in a row...

    KuddRoww Level 1




      I'd like to be able to turn the first table into the second. I see that there is a cell merge, but I can't seem to figure out the syntax.


      Thanks in advance for your help.

        • 1. Re: Merging cells in a row...
          KuddRoww Level 1


          • 2. Re: Merging cells in a row...
            KuddRoww Level 1

            If someone can think of a better answer I'll still give out points. Ultimately I'd love to be able to have a rowCellCount like the bodyRowCount in tables. C'est la vie.

            • 3. Re: Merging cells in a row...
              [Jongware] Most Valuable Participant

              rowCellCount is simply either rows.cells.length or rows.columns.length -- without trying, I think the first gives the actual count of cells in a row (merged or not), and the second the original number of columns.


              To merge, use http://jongware.mit.edu/idcs5js/pc_Cell.html#merge like this:


              table = app.selection[0];
              if (table.hasOwnProperty("baseline")) table = table.parent;
              if (table instanceof Cell) table = table.parent;
              if (table instanceof Column) table = table.parent;
              if (table instanceof Row) table = table.parent;
              if (table instanceof Table)
                        table.rows[0].cells[0].merge (table.rows[0].cells[1]);


              .. the first 6 lines are to make sure the script knows where it is. This way, it will work with the text cursor inside a cell (every text object has a "baseline" property; I think it's a trick I learned from Dave Saunders), or with a cell, column, row, or the entire table selected. After locating the table, it's just a matter of following the description of "Cells: Merge".


              Oh wait, now I have a table, 3 cells per row and the first 2 cells merged, to test my first assertion on. Running this


              alert (table.rows[0].cells.length);
              alert (table.rows[0].columns.length);
              alert (table.rows[1].cells.length);
              alert (table.rows[1].columns.length);


              alerts "2", "3", "3" and "3", just as I thought.

              1 person found this helpful
              • 4. Re: Merging cells in a row...
                KuddRoww Level 1

                Nifty! Great explanation. Much appreciated.