How to search for a 1 cell table

Everything related to our flagship word processor.
Post Reply
vwnisus
Posts: 27
Joined: 2016-04-24 00:13:31

How to search for a 1 cell table

Post by vwnisus » 2019-04-09 01:56:04

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.

User avatar
phspaelti
Posts: 999
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to search for a 1 cell table

Post by phspaelti » 2019-04-09 02:11:25

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
philip

User avatar
phspaelti
Posts: 999
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to search for a 1 cell table

Post by phspaelti » 2019-04-09 02:35:59

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.
philip

vwnisus
Posts: 27
Joined: 2016-04-24 00:13:31

Re: How to search for a 1 cell table

Post by vwnisus » 2019-04-09 03:19:15

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.

User avatar
phspaelti
Posts: 999
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to search for a 1 cell table

Post by phspaelti » 2019-04-09 04:12:10

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
philip

User avatar
martin
Official Nisus Person
Posts: 4488
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: How to search for a 1 cell table

Post by martin » 2019-04-09 13:37:42

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 1289 times
2. After you've found the matches use the menu Table > Delete > Table. That will completely excise the enclosing table or tables.

Post Reply