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?
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;
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;
}
}
Copy link to clipboard
Copied
function getRowNum( currRow )
{
var i = 0;
while( currRow.PrevRowInTbl.ObjectValid( ) )
{
currRow = currRow.PrevRowInTbl;
i++;
}
return i;
}
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.
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
Copy link to clipboard
Copied
Klaus,
FYI, you can also mark any other reply as "Helpful" if it contributes to solving your issue.