Skip to main content
January 18, 2013
Question

How to search text in the table?

  • January 18, 2013
  • 1 reply
  • 1079 views

Suppose, I've selected some fragment in my document, and I need to find and replace some text in it. Everything is ok, untill I select a part of a table with this text. Does anyone has idea, how to search through the selected cells in the table? Or, just how to iterate them?

Thanks!

This topic has been closed for replies.

1 reply

frameexpert
Community Expert
January 18, 2013

Here is how to interate through table cells in the selected table:

var doc = app.ActiveDoc;

var tbl = doc.SelectedTbl;

var cell = tbl.FirstRowInTbl.FirstCellInRow;

while (cell.ObjectValid() === 1) {

    // Do something with the cell object here.

    cell = cell.NextCellInTbl;

}

- Rick

January 18, 2013

Thanks for the answer, but isn't it iterating through entire table?

frameexpert
Community Expert
January 18, 2013

var doc = app.ActiveDoc;

var tbl = doc.SelectedTbl;

// Navigate to the first selected row.

var row = tbl.FirstRowInTbl;

while (row.ObjectValid() === 1) {

    if (row.id === tbl.TopRowSelection.id) {

        break;

    }

    row = row.NextRowInTbl;

}

// Process the selected rows.

while (row.ObjectValid() ===1) {

    cell = row.FirstCellInRow;

    while (cell.ObjectValid() === 1) {

        if ((cell.CellColNum >= tbl.LeftColNum) && (cell.CellColNum <= tbl.RightColNum)) {

            // Do something here...

        }

        cell = cell.NextCellInRow;

    }

    if (row.id === tbl.BottomRowSelection.id) {

        break;

    }

    row = row.NextRowInTbl;

}

This should do what you want.

Rick