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

How to search text in the table?

Guest
Jan 18, 2013 Jan 18, 2013

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

900

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 ,
Jan 18, 2013 Jan 18, 2013

Copy link to clipboard

Copied

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

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
Guest
Jan 18, 2013 Jan 18, 2013

Copy link to clipboard

Copied

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

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 ,
Jan 18, 2013 Jan 18, 2013

Copy link to clipboard

Copied

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

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
Guest
Jan 18, 2013 Jan 18, 2013

Copy link to clipboard

Copied

Thanks, that seems way closer to the solution, but there still few things left.

1. Just for case, can we select row partly? And if yes, how should we act then?

2. What if there're more than 1 table in the selection?

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 ,
Jan 18, 2013 Jan 18, 2013

Copy link to clipboard

Copied

LATEST

1. The script already does this; it only processes the cells that are selected.

2. If there are more than one table in the selection, then you are basically back to interating through all of the cells in each table.

Here is how you can get a list of the tables that are selected in document:

var doc = app.ActiveDoc;

// Get all of the tables that are selected.

var textList = doc.GetTextForRange (doc.TextSelection, Constants.FTI_TblAnchor);

alert (textList.len);

I don't have time right now to give you any more details, but I may be able to later.

-Rick

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