1 Reply Latest reply: Dec 10, 2010 4:34 AM by Marijan Tompa RSS

    How to swap the contents between the columns?

    Praveen10 Community Member

      Hi,

       

      I've two columns in each page, and I need to swap the contents in 1st column into 2nd column and vice versa. Pl. suggest me the way to achieve this requirement and confirm whether any option available in script?

       

      Thanks in advance.

       

      Praveen

        • 1. Re: How to swap the contents between the columns?
          Marijan Tompa MeganK

          Hey!

           

          This swaps just data, not formatting.

           

          // this will swap first and third column
          swapColumns(1,3);
          
          var myTable = (function(){
              if(app.selection[0].parent.parent instanceof Table)
                  return app.selection[0].parent.parent;
              else
                  return app.selection[0].parent;
                  })();
          
          function swapColumns(sourceCol, destCol){
              if(sourceCol == destCol)exit();
              var sourceColCont = myTable.columns[sourceCol-1].contents;
              var destColCont = myTable.columns[destCol-1].contents;
              myTable.columns[destCol-1].contents = sourceColCont;
              myTable.columns[sourceCol-1].contents = destColCont;
          }
          

           

          Hope that helps.

           

          --

          tomaxxi

          http://indisnip.wordpress.com/