• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Get row and col nr of current cell

Community Expert ,
Oct 31, 2016 Oct 31, 2016

Copy link to clipboard

Copied

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?

TOPICS
Scripting

Views

374

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 31, 2016 Oct 31, 2016

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;

   

 

...

Votes

Translate

Translate
Community Expert ,
Oct 31, 2016 Oct 31, 2016

Copy link to clipboard

Copied

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;

    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 31, 2016 Oct 31, 2016

Copy link to clipboard

Copied

function getRowNum( currRow )

{

     var i = 0;

     while( currRow.PrevRowInTbl.ObjectValid( ) )

     {

          currRow = currRow.PrevRowInTbl;

          i++;

     }

     return i;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 01, 2016 Nov 01, 2016

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 01, 2016 Nov 01, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 01, 2016 Nov 01, 2016

Copy link to clipboard

Copied

LATEST

Klaus,

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines