Highlighted

Get row and col nr of current cell

Advocate ,
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?

Adobe Community Professional
Correct answer by frameexpert | Adobe Community Professional

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;

    }

}

TOPICS
Scripting

Views

254

Likes

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

Get row and col nr of current cell

Advocate ,
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?

Adobe Community Professional
Correct answer by frameexpert | Adobe Community Professional

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;

    }

}

TOPICS
Scripting

Views

255

Likes

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
Oct 31, 2016 0
Adobe Community Professional ,
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;

    }

}

Likes

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
Reply
Loading...
Oct 31, 2016 1
Advocate ,
Oct 31, 2016

Copy link to clipboard

Copied

function getRowNum( currRow )

{

     var i = 0;

     while( currRow.PrevRowInTbl.ObjectValid( ) )

     {

          currRow = currRow.PrevRowInTbl;

          i++;

     }

     return i;

}

Likes

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
Reply
Loading...
Oct 31, 2016 1
Advocate ,
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.

Likes

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
Reply
Loading...
Nov 01, 2016 0
Advocate ,
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

Likes

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
Reply
Loading...
Nov 01, 2016 0
Most Valuable Participant ,
Nov 01, 2016

Copy link to clipboard

Copied

Klaus,

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

Likes

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
Reply
Loading...
Nov 01, 2016 0