7 Replies Latest reply on Jan 18, 2014 12:24 PM by Liphou

    [JS]  Test fused cells (merge)

    Liphou Level 1

      Hello,

      Is it possible to test whether a cell is merged?

      Yours

       

      Bonjour,

       

      Est-il possible de tester si une cellule est fusionner?

       

      Bien à vous

        • 1. Re: [JS]  Test fused cells (merge)
          Peter Kahrel Adobe Community Professional & MVP

          Check columnSpan and/or rowSpan. From memory:

           

          if (myCell.rowSpan > 0) {

             // merged rows

          }

           

          and

           

          if (myCell.columnSpan > 0) {

             // merged columns

          }

          • 2. Re: [JS]  Test fused cells (merge)
            Liphou Level 1

            That's great!

            Super  c'est ça!!!

            • 3. Re: [JS]  Test fused cells (merge)
              Laubender Adobe Community Professional & MVP

              @Philippe – test a cell for "rowSpan" and "columnSpan", together with its "name" string and "id" (unique for the table) you can determine if the cell in merged, where it starts and ends in horizontal and vertical orientation.

               

              It also would help to get the number of rows and number of columns to get the basic "grid" right.

               

              The id numbers are especially interesting. If cells are merged numbers will be missing.

               

              Example:
              A  4 x 3 table where the first cell is merged with the cell below.

               

              A loop through all cells by rows like that:

               

              for(var n=0;n<myTable.rows.length;n++){
                  $.writeln(myTable.rows[n].cells.everyItem().id);
                  $.writeln(myTable.rows[n].cells.everyItem().name);
                  $.writeln(myTable.rows[n].cells.everyItem().rowSpan);
                  $.writeln(myTable.rows[n].cells.everyItem().columnSpan);
                  };
              

               

              will reveal:

               

              Matrix of id-numbers:

               

              0, 1,  2,  3

                  5,  6,  7

              8, 9,10,11

               

              cells.itemByID(0).rowSpan is 2.

              cells.itemByID(4) does not exist.

               

               

              Matrix of names:

               

              0:0, 1:0, 2:0, 3:0

                     1:1, 2:1, 3:1

              0:2, 1:2, 2:2, 3:2

               

              There is no cell named "0:1"

               

              Matrix of rowSpan:

               

              2, 1, 1, 1

                  1, 1, 1

              1, 1, 1, 1

               

              Matrix of columnSpan:

               

              1, 1, 1, 1

                  1, 1, 1

              1, 1, 1, 1

               

               

              //A table is selected:
              
              var myTable = app.selection[0];
              
              howManyCellsOfTheTableGridAreMerged(myTable);
              
              //Simple function:
              
              function howManyCellsOfTheTableGridAreMerged(myTable){
                  
                  var columnOrRowMerged = 0;
              
                  var c = myTable.columns.length;
                  var r = myTable.rows.length;
                  
                  var gridLength = c * r ;
                  var myCellLength = myTable.cells.length;
                  
                  var diff = gridLength - myCellLength;
                  
                  for(var n=0;n<myTable.cells.length;n++){
                      if(myTable.cells[n].rowSpan > 1 || myTable.cells[n].columnSpan > 1){
                          ++columnOrRowMerged;
                          };
                      };
                  
                  return diff + columnOrRowMerged;
                  
                  };
              

               

              I used the term "table grid" to describe the "ideal" table where no cells are merged.

               

              Tested this simple function on our example table, it will return: 2

              (if you look at the ideal table grid, the 4 x 3 matrix: cells[0] is merged with cells[4] )

               

              That should get you some ideas…

               

              Uwe

              • 4. Re: [JS]  Test fused cells (merge)
                Liphou Level 1

                Super  merci  Laubender .

                • 5. Re: [JS]  Test fused cells (merge)
                  Liphou Level 1

                  Another small question, I am in a painting, I want to have the style name is paragaphe or inserts the table and applied a different sytle.

                  this command:

                  $.writeln (leTableau.parent.appliedParagraphStyle.name); // -> TextFrame $.writeln (leTableau.parent.constructor.name); // fait une erreur normal!

                   

                   

                  Une autre petit question, je suis bien dans un tableau, je veux  s'avoir  le nom du style de paragaphe ou est insére le tableau et appliqué un autre sytle.

                   

                  cet commande :

                  $.writeln (leTableau.parent.appliedParagraphStyle.name); // -> TextFrame $.writeln (leTableau.parent.constructor.name); // fait une erreur normal!

                   

                   

                  Merci

                  • 6. Re: [JS]  Test fused cells (merge)
                    TᴀW Adobe Community Professional & MVP

                    You want storyOffset:

                     

                    myTable.storyOffset

                     

                    gives you the insertionPoint before the table in the story containing the table.

                    • 7. Re: [JS]  Test fused cells (merge)
                      Liphou Level 1

                      Thank you and I control this réaplique another Style

                       

                      leTableau.storyOffset.appliedParagraphStyle = 'centreP';

                       

                      Merci et avec cet commande je réaplique un autre Style

                       

                      leTableau.storyOffset.appliedParagraphStyle = 'centreP';