9 Replies Latest reply on Jul 18, 2013 4:41 AM by DaveSofTypefi

    not able to merge table cells

    ajay259

      hello forum,

       

      i am using Indesign 5.5, having problem to merge table cells through scripting.

       

      i want to merge multiple cells in a table.

      i have merge first three merge coorectly, but my script not able to merge forth merge.

       

      i am using,

       

      var myDocument=app.activeDocument;

      var myTextFrame=myDocument.spreads.item(0).textFrames.item("Spread0TxtFrame0");

      var table =myTextFrame.tables.firstItem();

       

      var t = table.rows.length;

      var f = table.rows.length - (t-start row count) // **start row count is intiger indicates merge start row

      var fn=table.rows.length - (t-end row count)

       

      table.columns[1].cells[f].merge table.columns[2].cells[fn];      ////* [1]=starting column,,,[2]= end column

       

       

      when i does pass the value for first three merge it works but when i use for forth merge indxing is change for value of rows.what i am passing into f and fn.

       

      example:-

      var t = table.rows.length;

      var f = table.rows.length - (t-0);

      var fn=table.rows.length - (t-5);

      table.columns[0].cells[f].merge table.columns[0].cells[fn];   // it is for first merge

       

       

      var t = table.rows.length;

      var f = table.rows.length - (t-0);

      var fn=table.rows.length - (t-0);

      table.columns[2].cells[f].merge table.columns[3].cells[fn];   // it is for second merge

       

       

      var t = table.rows.length;

      var f = table.rows.length - (t-1);

      var fn=table.rows.length - (t-1);

      table.columns[1].cells[f].merge table.columns[2].cells[fn];   // it is for third merge

       

       

      var t = table.rows.length;

      var f = table.rows.length - (t-3);

      var fn=table.rows.length - (t-3);   

      table.columns[1].cells[f].merge table.columns[3].cells[fn];   // it is for forth merge

       

      i get

      an extra row merges with forth one..

       

       

      seperately all four merge works but when i fire script with all it merge wrong cells in forth merge.

       

      please correct me where i am wrong in script.

      your answer will be apriciated.

       

      Thanks

      Ajay

        • 1. Re: not able to merge table cells
          DaveSofTypefi Level 2

          How many rows does this table have in the first place? The most likely problem is that because of the previous merges the number of rows left is such that there aren't enough rows left for f to be formed properly.

           

          I may be off base here because I can't see the screen captures you tried to post.

           

          Dave

          • 2. Re: not able to merge table cells
            ajay259 Level 1

            hello dev,

             

            i have 6 rows and 4 columns no footer no header,

             

            and i did merge

             

            1st mergecell:- from row1 column1  to  row6 column1

            here is the syntax:-

             

            var t = table.rows.length;

            var f = table.rows.length - (t-0);

            var fn=table.rows.length - (t-5);

            table.columns[0].cells[f].merge table.columns[0].cells[fn];

             

            2nd mergecell:- from row1 column3 to row1 column4

             

            syntax:-

             

            var t = table.rows.length;

            var f = table.rows.length - (t-0);

            var fn=table.rows.length - (t-0);

            table.columns[2].cells[f].merge table.columns[3].cells[fn];

             

            3rd mergecell:- from row2 column2 to row2 column3

             

            syntax:-

             

            var t = table.rows.length;

            var f = table.rows.length - (t-1);

            var fn=table.rows.length - (t-1);

            table.columns[1].cells[f].merge table.columns[2].cells[fn];

             

            4rt mergecell:- from row4 column2 to row4 column4

             

            i use

            var t = table.rows.length;

            var f = table.rows.length - (t-3);

            var fn=table.rows.length - (t-3);    // problem is here it takes (t-2) instead of (t-3)

            table.columns[1].cells[f].merge table.columns[3].cells[fn];

             

            ** all value having 0 indexing

            • 3. Re: not able to merge table cells
              ajay259 Level 1

              want_tab.JPGmaintab.JPG

              dear dev i have upload three images of tables

               

              1- main_tab means what is my actual table

              2- want_tab- which i need to convert my table

              3-after_script_tab- this is the converted table after using my scripting

               

              after_scripting_tab.JPG

              • 4. Re: not able to merge table cells
                Jump_Over Level 5

                Hi,

                 

                Notice before merge 4 that your

                 

                table.columns[3].rows.length IS NOT EQUAL to table.columns[3].cells.length;

                (6 != 5)

                 

                I suggest to set your merge horizontally

                (i.e using: table.rows[f].cells[1] instead of table.columns[1].cells[f])

                 

                ______________________

                edited: wrong suggestion!!!

                     since you are editing a table vertically first -

                     its rows[0].cells.length == 4 and the rest of rows.cells.length ==3

                 

                     With your particular goal:

                     move merge 1 to the end of steps

                 

                Jarek

                • 5. Re: not able to merge table cells
                  ajay259 Level 1

                  hello jarek,,

                   

                   

                  you are right for my perticular case

                   

                  but my script comes out from code sequentially merge1 to merge 4

                   

                  how could i apply 1st merge in end

                   

                  i am talking about various tables and their merges

                   

                   

                   

                   

                  thanks

                  ajay

                  • 6. Re: not able to merge table cells
                    ajay259 Level 1

                    hello dave,,

                     

                     

                    i am waiting for your response, please find the attachment tables and take a overview on situation.

                    • 7. Re: not able to merge table cells
                      ajay259 Level 1

                      hi,

                       

                       

                      dear i just want to know how will i find or get the return value of any variable in java script through indesign object model??

                       

                       

                      ex- "var tab= table.rows.length;"

                       

                      i just want to know the return value in variable "tab" while debug the script.

                      • 8. Re: not able to merge table cells
                        ajay259 Level 1

                        hi,

                         

                         

                        dear i  want to know how will i find or get the return value of any variable in java script through indesign object model??

                         

                         

                        ex- "var tab= table.rows.length;"

                         

                        i just want to know the return value in variable "tab" while debug the script.

                        • 9. Re: not able to merge table cells
                          DaveSofTypefi Level 2

                          Your posted script has syntax errors so I couldn't find what you were doing wrong because the script won't run as posted. Can you post a version that actually exhibits the problem you're trying to solve.

                           

                          But, from what has gone before, you're probably overlooking the fact that your script is changing the number of rows as it does each step so what you think of as static values are actually changing during the course of the script.

                           

                          Dave