8 Replies Latest reply on Aug 31, 2012 3:49 AM by Laubender

    [JS, ID5 SVR] select row containing vertically merged cells

    stoereee Level 1

      Hello,

       

      I want to set row type to rows containing vertically merged cells. Example of rows with merged cells:

       




























       

      When a row defined as myTable.rows[1], it returns an error. How to approach the second and third row?

       

      Regards, Sjoerd

        • 2. Re: [JS, ID5 SVR] select row containing vertically merged cells
          csm_phil Level 4

          Hi Serjod,

           

          I have alredy infrom to you, Whatever, you need just post what you have been tried in JS code, You always post the snapshots and ask please create the code. This is not a good sign to develop your knowledge.

           

          Please take my suggestion!

           

          thx,

          csm_phil

          • 3. Re: [JS, ID5 SVR] select row containing vertically merged cells
            stoereee Level 1

            I have alredy infrom to you, Whatever, you need just post what you have been tried in JS code, You always post the snapshots and ask please create the code. This is not a good sign to develop your knowledge.

             

            Where and when did you informed me!? And take a look at my former posts. Generally I post some code with it... But anyway, here's a sample of the code that isn't working with vertically merged cells:

             

            var myDoc = app.activeDocument;
            var myTables = myDoc.stories.everyItem().tables.everyItem().getElements();
            
            for (i=0; i<myTables.length; i++) {
                var myActiveTable = myTables[i];
                var myRow;
                for (myRow=0; myRow<myActiveTable.rows.length; myRow++) {
                    var myFillColor = myActiveTable.rows[myRow].cells[0].fillColor;
                    if (myActiveTable.rows[myRow].cells[0].fillColor == myColor && myActiveTable.rows[myRow].cells[0].fillTint == 40) {
                        myActiveTable.rows[1].cells.everyItem().fillColor = "Blue";
                        }
                        }
                    }
                }
            
            • 4. Re: [JS, ID5 SVR] select row containing vertically merged cells
              [Jongware] Most Valuable Participant

              Hi Sjoerd,

               

              Your sample code appears to work on the sample table in the first post ... But in other configurations of merged cells your script might have a problem.

              This problem is the following: not every row is guaranteed to have a '0' numbered cell -- it depends on how you are counting!

               

              If you loop over all cells in a table and you fill in its index number, you get what you'd expect: a continuous list from 0..number of visible cells, progressing in a logical fashion from left to right and top to bottom -- taking merged cells into account as well.

              However, if you inspect the logical row/column number per cell, you will find some numbers are missing.

               

              table = app.selection[0];
              if (table.hasOwnProperty("baseline")) table = table.parent;
              while (table instanceof Cell || table instanceof Column || table instanceof Row)
               table = table.parent;
              if (table instanceof Table)
              {
              // for (i=0; i<table.cells.length; i++)
              //  table.cells[i].contents = String(i);
               for (i=0; i<table.cells.length; i++)
                table.cells[i].contents = String(table.cells[i].parentRow.index)+":"+String(table.cells[i].parentColumn.index);
              }
              

              tabel-cells.PNG

              So you would think addressing row #2, cell #0 would return an error. Well, you'd think wrong! I'm unable to get the error you mentioned, simple tests seem to work for me on this table. If you do this

               

              alert (table.rows[2].cells[0].contents);

               

              you do not get an error; you'll see "2:1" (which is the first cell on row #2). So I cannot replicate your exact error. Perhaps you have some other configuration of merged cells where it does fail, or perhaps my simplified script doesn't address cells and rows the exact same thing as yours.

              • 5. Re: [JS, ID5 SVR] select row containing vertically merged cells
                stoereee Level 1

                Jongware,

                 

                With the following script:

                 

                var myDoc = app.activeDocument;
                
                var myTables = myDoc.stories.everyItem().tables.everyItem().getElements();
                
                for (i=0;i<myTables.length;i++) {
                var myActiveTable = myTables[i];
                var row, cell;
                for (row=0;row<myActiveTable.rows.length;row++) {
                for (cell=0;cell<myActiveTable.rows[row].cells.length;cell++) {
                     if (myActiveTable.rows[1].cells[cell].insertionPoints[0].appliedParagraphStyle.name == "Table-Title") {
                     myActiveTable.rows[1].cells.everyItem().appliedCellStyle = "Table-Title-2";
                     }
                

                 

                and this table:

                 




















                 

                the debugger returns an error at:

                 

                myActiveTable.rows[1].cells[cell].insertionPoints[0].appliedParagraphStyle.name == "Table-Title"
                

                 

                With the above table and script a want to search for a row containing the paragraph style "Table-Title" and if yes, then apply a cell style.

                 

                Regards, Sjoerd

                • 6. Re: [JS, ID5 SVR] select row containing vertically merged cells
                  stoereee Level 1










                   

                  It is still bordering me. When I want to apply a cell style (thick line under) to the last cells in a column, I get stuck with the first column because it has got vertically merged cells. With the following script only column 2 and 3 get the cell style:

                   

                  myActiveTable.rows.lastItem().cells.everyItem().appliedCellStyle = "Line-under";
                  

                   

                  How can I apply the cell style to the last cell in the row of the first column?

                   

                  Regards, Sjoerd

                  • 7. Re: [JS, ID5 SVR] select row containing vertically merged cells
                    stoereee Level 1

                    How simple can it be:

                     

                    var myDoc = app.activeDocument;
                    
                    var myTables = myDoc.stories.everyItem().tables.everyItem().getElements();
                    
                    for (i=0;i<myTables.length;i++) {
                    var myActiveTable = myTables[i];
                    
                    for (j=0;j<myActiveTable.columns.length;j++) {
                        alert(myActiveTable.columns[j].cells.length);
                        myActiveTable.columns[j].cells.lastItem().appliedCellStyle = "Lijn";
                    }
                    }
                    

                     

                    I'm a rookie, that's for sure...

                    • 8. Re: [JS, ID5 SVR] select row containing vertically merged cells
                      Laubender Adobe Community Professional & MVP

                      How can I apply the cell style to the last cell in the row of the first column?

                       

                      With "everyItem()" you can do that directly without looping through "myTables":

                       

                      myDoc.stories.everyItem().tables.everyItem().columns[0].cells[-1].appliedCellStyle = "Lijn";
                      

                       

                      Uwe