5 Replies Latest reply on Jul 19, 2010 7:15 AM by Loic.Aigon

    [JS] select several rows in a table

    Loic.Aigon Adobe Community Professional

      Hi Guys,

       

      Is there a way to select several rows in a table ? If I pass an array of rows reference to the app.select() method, it fails.

       

      For one that's ok but not for two or more. That rows are next to each other don't chnge a thing.

       

      var t = ....tables[0] //a given reference to a table
      app.select([t.rows[1], t.rows[2], t.rows[3]])
      //Error > Expected array of objects but received (Row,Row,Row)
      

       

      app.select(t.rows[1]) works great. But when I want to select several rows it doesn't.

       

      Any advice ?

       

      TIA Loic

        • 1. Re: [JS] select several rows in a table
          Marijan Tompa [tomaxxi] Level 4

          Hey!

           

          Try selecting each row separatly:

           

          var myT = app.selection[0].tables[0];
          myT.rows[0].select();
          myT.rows[1].select(SelectionOptions.ADD_TO);
          

           

           

          tomaxxi

          1 person found this helpful
          • 2. Re: [JS] select several rows in a table
            [Jongware] Most Valuable Participant

            I couldn't get it to work either -- but the important question here is "why would you want to select them?" You don't need a selection to change its properties; this snippet works just fine, and it does not need to change the selection.

             

            myRange = t.rows.itemByRange(1,3);
            myRange.fillColor = "Black";

            1 person found this helpful
            • 3. Re: [JS] select several rows in a table
              Loic.Aigon Adobe Community Professional

              Hi Theunis, Tomaxxi,

               

              Using itemByRange is certainly helpful to act on several cells at once. But my intention is to grab the contents of these cells to copy/paste in another place.

               

              I could use rows.itemByRange(n,n).contents but it seems contents is a property that donesn't handle other contents than strings. If my cell include graphic frame, this is unoperant. But maybe I am wrong.

               

              So far, Tomaxxi's way seems to be the good way for me.

               

              Thanks for all your help on that topic to both of you.

               

              Loic

              • 4. Re: [JS] select several rows in a table
                [Jongware] Most Valuable Participant

                I was going to say, "you can use .duplicate to copy parts around" ... but ... neither Table, nor Row, nor Cell has a .duplicate method! W00t!?

                 

                But you are correct on the .contents property -- it's just the text inside cells, converted to unformatted Javascript strings. I think applying it to a row might cause trouble, though.

                You can still use the .text property, which does include inline graphics and all the rest -- but it's a property of cells, not of rows. This quick experiment worked:

                 

                table = app.selection[0].parentStory.tables[1];
                table.rows.itemByRange(1,3).cells.everyItem().texts.everyItem().duplicate(LocationOptions. AFTER, app.selection[0]);

                but you get the text of all cells and rows in one long line ... so you'd have to loop over rows and cells 'manually' ...

                1 person found this helpful
                • 5. Re: [JS] select several rows in a table
                  Loic.Aigon Adobe Community Professional

                  Hmmm, I did not know texts include inline graphics. Good to know ! :-)

                   

                  I finally wrote that function

                  function selectRows(aTable, startRowIndex, endRowIndex){
                       app.selection = NothingEnum.NOTHING;
                       var _row = aTable.rows;
                       app.select(_row[startRowIndex-1]);
                       for(var i=startRowIndex; i<endRowIndex;i++){
                            app.select(_row[i], SelectionOptions.ADD_TO);
                       }
                  }
                  

                   

                  So I give a table and row delimiters to select the Contents.

                  In the end, I get something like

                  selectRows(srcTable, 2,3);
                  app.copy();
                  app.selection = NothingEnum.NOTHING;
                  selectRows(destTable, 2,3);
                  app.paste();
                  app.selection = NothingEnum.NOTHING;

                   

                  It does what I want.

                   

                  Thanks Theunis for your interest on that topic.

                  Loic

                  1 person found this helpful