2 Replies Latest reply on Apr 4, 2017 8:56 AM by Trevorׅ

    Change Row-type

    cmoke73 Level 1

      Hello everybody.

       

      It is really a simple thing. And for me it makes sense like I wrote that script. Unfortunatly: it does not work . Where is my error in reasoning?

       

      ...

      if (myTables.rows.firstItem().rowType == RowTypes.BODY_ROW) { 
           myTables.rows[0].rowType = RowTypes.HEADER_ROW; ) 
      } 
      if (myTables.rows[-1].rowType == RowTypes.BODY_ROW) { 
           myTables.rows[-1].rowType = RowTypes.FOOTER_ROW; 
      }  
      

      ...

       

      Nothing will be detected betweeen the parantheses. --> The condition has no function. There is no error-message too.

        • 1. Re: Change Row-type
          Kasyan Servetsky Level 5

          I see only one problem in your code: the line 2 has a closing round bracket at the end.

          Otherwise it works for me on my InDesign CC 2015 for Mac.

          main();
          
          function main() {
              var myTables = app.selection[0]; // Let's assume a table is selected
              
              if (myTables.rows[0].rowType == RowTypes.BODY_ROW) {   
                   myTables.rows[0].rowType = RowTypes.HEADER_ROW;  
              }   
              if (myTables.rows[-1].rowType == RowTypes.BODY_ROW) {   
                   myTables.rows[-1].rowType = RowTypes.FOOTER_ROW;   
              }
          }
          

           

          Also, I recommend you to use rows[0] instead of rows.firstItem() because it's faster.

           

          — Kas

          • 2. Re: Change Row-type
            Trevorׅ Adobe Community Professional

            If you have a cell selected then the following code works

            myTables = app.selection[0].parent;
            if (myTables.rows[0].rowType == RowTypes.BODY_ROW) {   
                 myTables.rows[0].rowType = RowTypes.HEADER_ROW;   
            }   
            if (myTables.rows[-1].rowType == RowTypes.BODY_ROW) {   
                 myTables.rows[-1].rowType = RowTypes.FOOTER_ROW;   
            }
            

             

            Check that your "myTables" is really a table, alert(myTables)