5 Replies Latest reply on Jan 18, 2013 9:22 AM by frameexpert

    How to search text in the table?

    TauChiba

      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!

        • 1. Re: How to search text in the table?
          frameexpert Level 4

          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

          1 person found this helpful
          • 2. Re: How to search text in the table?
            TauChiba Level 1

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

            • 3. Re: How to search text in the table?
              frameexpert Level 4

              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

              1 person found this helpful
              • 4. Re: How to search text in the table?
                TauChiba Level 1

                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?

                • 5. Re: How to search text in the table?
                  frameexpert Level 4

                  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