5 Replies Latest reply on Nov 1, 2016 8:17 AM by Arnis Gubins

    Get row and col nr of current cell

    K.Daube Level 1

      Dear all,

      For absolute addressing a table cell out of the current cell I need to know where I am.

      I have not found a proporty like CurrentRow or CellRowNum. CellRow is an object Row.

      // CellNumbering.jsx
      // have cursor in a table cell
      #target framemaker
        oDoc  = app.ActiveDoc;
        oTbl  = oDoc.SelectedTbl;
        oPgf  = oDoc.TextSelection.beg.obj;  
        oCell = oPgf.InTextObj; 
        
      //jRow  = oCell.???;              // ???
        jCol  = oCell.CellColNum;       // 0 ... n
      $.writeln (oTbl.TblNumCols);      // 4
      $.writeln (jCol);                 // 2
      

      Is it necessary to loop through all rows and cells to find the currentselection => current location found?

        • 1. Re: Get row and col nr of current cell
          frameexpert Level 4

          Hi Klaus,

           

          Rows don't have a number property, so you would have to start at the top of the table and count down to the current row. You could use something like this:

           

          #target framemaker
          
          var doc = app.ActiveDoc;
          var tbl = doc.SelectedTbl;
          var pgf = doc.TextSelection.beg.obj;
          var cell = pgf.InTextObj;
          var row = cell.CellRow;
          
          // Get the row number (first row is 0).
          var rowNum = getRowNum (tbl, row);
          alert (rowNum);
          
          function getRowNum (tbl, currRow) {
              
              var row = tbl.FirstRowInTbl;
              var counter = 0;
              
              while (row.ObjectValid () === 1) {
                  if (row.id === currRow.id) {
                      return counter;
                  }
                  counter += 1;
                  row = row.NextRowInTbl;
              }
          }
          
          1 person found this helpful
          • 2. Re: Get row and col nr of current cell
            4everJang Level 3
            function getRowNum( currRow )
            {
                 var i = 0;
                 while( currRow.PrevRowInTbl.ObjectValid( ) )
                 {
                      currRow = currRow.PrevRowInTbl;
                      i++;
                 }
            
                 return i;
            }
            
            1 person found this helpful
            • 3. Re: Get row and col nr of current cell
              K.Daube Level 1

              Many thanks both to Ric and Jang!

              I could mark only 1 as Correct Answer

              I will make a CurrentCellNum function to have the indexing the same for both row and column.

                jRow  = GetRowNum (oRow);               // 1 ... n
                jCol  = oCell.CellColNum;               // 0 ... m
              

              This would be prone to erraneous use.

              • 4. Re: Get row and col nr of current cell
                4everJang Level 3

                Klaus, don't worry about only marking Rick's answer as correct. I am only in it for the money, not the points

                • 5. Re: Get row and col nr of current cell
                  Arnis Gubins Adobe Community Professional & MVP

                  Klaus,

                   

                  FYI, you can also mark any other reply as "Helpful" if it contributes to solving your issue.