Page 1 of 1

How to search for a 1 cell table

Posted: 2019-04-09 01:56:04
by vwnisus
I have to download a number of rtf files - each of them appear to contain a number of 1 cell tables with a boarder, and containing the same text ("Document Information").

Is it possible to search for this. I have tried copying the table into the Search box but doing so only copies the text and not the table information.

Attached is an extract from the file showing what is involved. Any help would be gratefully received.

Re: How to search for a 1 cell table

Posted: 2019-04-09 02:11:25
by phspaelti
Since they all have the same text, wouldn't searching for the text work? What do you want to do with them when you find them?

Macro code for finding one cell tables would be as follows:

Code: Select all

$doc = Document.active
$oneCellTables = Array.new
foreach $table in $doc.text.tables
  if ($table.rowCount == 1) && ($table.columnCount == 1)
    $oneCellTables.push $table
  end
end
$doc.setSelection $oneCellTables

Re: How to search for a 1 cell table

Posted: 2019-04-09 02:35:59
by phspaelti
For instance you could follow up the code above with the following:

Code: Select all

foreach $table in reversed $oneCellTables
  $cell = $table.cellAtRowAndColumn(0,0)
  $cellText = $cell.text.copy & "\n"
  $lineAttrsTop = $cell.lineAttributesForEdge 'top'
  $lineAttrsBottom = $cell.lineAttributesForEdge 'bottom'
  $lineAttrsRight = $cell.lineAttributesForEdge 'right'
  $lineAttrsLeft = $cell.lineAttributesForEdge 'left'
  $text = $table.enclosingText
  $loc = $table.enclosingTextRange.location
  $text.replaceInRange $table.enclosingTextRange, $cellText
  $paraRange = $text.rangeOfParagraphAtIndex($loc)
  $doc.setSelection TextSelection.new($text, $paraRange)
  Set Paragraph Line Attributes For Edges $lineAttrsTop, 'top'
  Set Paragraph Line Attributes For Edges $lineAttrsBottom, 'bottom'
  Set Paragraph Line Attributes For Edges $lineAttrsRight, 'right'
  Set Paragraph Line Attributes For Edges $lineAttrsLeft, 'left'
end
Which should remove the tables and turn them into paragraphs while preserving the border formatting.

Re: How to search for a 1 cell table

Posted: 2019-04-09 03:19:15
by vwnisus
Thank you for the replies.

I will try the macros you have provided.

The intention is to remove the text and the table.

Doing a search just for the text and replacing it with nothing, leaves the table.

Re: How to search for a 1 cell table

Posted: 2019-04-09 04:12:10
by phspaelti
vwnisus wrote:
2019-04-09 03:19:15
The intention is to remove the text and the table.
Well in that case, use the first macro and press "delete". Though that might result in merged paragraphs. So maybe better:

Code: Select all

foreach $table in reversed $oneCellTables
  $table.enclosingText.replaceInRange $table.enclosingTextRange, "\n"
end

Re: How to search for a 1 cell table

Posted: 2019-04-09 13:37:42
by martin
There's an easy non-macro way to accomplish the same task:

1. Use the Find panel to select the desired text. If you only want to match text inside of tables then set the "Where" option to Tables:
where.png
where.png (25.7 KiB) Viewed 2986 times
2. After you've found the matches use the menu Table > Delete > Table. That will completely excise the enclosing table or tables.