Ask Your Question
0

Find & Replace the last empty paragraph in a table cell

asked 2020-12-24 22:05:46 +0100

LeroyG gravatar image

updated 2020-12-30 19:00:49 +0100

Hello everyone,

I received a document with many tables. Many cells ends with an empty paragraph. I don't realize how to delete them (regardless scroll down and delete one by one).

Nothing normal I tried with in Regular expressions, finds it: no with ^$, no with $, no with "$".

Tested various combinations from ICU Regular Expression Metacharacters (\v, \n, \r, \R, \t, \f, \Z, \z) (by the way, learned new things), readed /question/217622/, but…

image description

Original document is .docx, but I tested with a new document in Writer with the same without any result.

Thank in advance.

LibreOffice 6.4.7.2 (x86); OS: Windows 6.1.

edit retag flag offensive close merge delete

Comments

Did you try $ by itself? You did. In my test table it worked for deleting all extra returns that didn't have text on the same line. Cheers, Al

Earnest Al gravatar imageEarnest Al ( 2020-12-25 07:21:09 +0100 )edit

For me, this deletes all end of paragraphs.

LeroyG gravatar imageLeroyG ( 2020-12-25 13:12:35 +0100 )edit

For me it doesn't (and never did).
Just now I tested again with LibO 7.0.3.1. F&R doesn't remove the last emtpy paragraph of any text object, whether it is the document's main text, a TextTable cell, or the text of a TextFrame.
I searched for empty paragraphs with ^$ and succeeded always except with the final paragraph.

How should I understand the different experiences?

BTW: If the text object has at least one additional paragraph, the last one can also be removed by user code. Having placed a TextCursor tc at the .End of that text, tc.Text.removeTextContent(tc.TextParagraph) worked for me as expected.

Lupp gravatar imageLupp ( 2020-12-25 15:14:11 +0100 )edit

@Lupp,

all end of paragraphs.

Not the same that empty paragraphs.

"user code" ≈ macro?

LeroyG gravatar imageLeroyG ( 2020-12-25 15:52:03 +0100 )edit

@Earnest Al and @Lupp, Thanks for the support!

LeroyG gravatar imageLeroyG ( 2020-12-25 16:05:46 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2020-12-25 15:56:53 +0100

LeroyG gravatar image

Solved it after reading @Lupp comment, but with another workaround.

  • Replaced all $ with (could be another character not used in the text).
  • Replaced all █$ with `` (nothing).
  • Replaced all with \n.

Add Answer is reserved for solutions. If you think the answer is not satisfactory, add a comment below. Thanks.

If the answer helped you, you can mark the up arrow (Upvote mark) that is on the left (to vote, you need to have karma of at least 5).

edit flag offensive delete link more

Comments

You (@LeroyG) surely know yourself. Just for users visiting this thread searching for a solution to their similar questions:
This doesn't remove the trailing empty paragraph. It removes all the paragraph breaks, and then recreates paragraphs, all of them based on the first one that wasn't removed, but got appended the string content of the others.
As long as paragraph styles, direct paragraph formatting, and page layout don't matter, you can do it this way.

Lupp gravatar imageLupp ( 2020-12-30 20:12:30 +0100 )edit

The last paragraph "mark" in any flow (main text, frame, table cell, ...) is treated specially. It is a mandatory delimiter ending the flow. As a consequence, it can never be deleted.

@LeroyG's trick plays with all para marks other than the last. The main drawback is the trick removes all paragraph styles (except the one in effect at the beginning of text). This ruins all formatting.

ajlittoz gravatar imageajlittoz ( 2020-12-31 07:50:11 +0100 )edit

You cannot delete the "mark", but -using the API- the paragraph calling .myText.removeTextContent(myParagraph), where myText must be the text object the myParagraph is content of.
Since any text cannot be empty on the first level of enumeration, the mentioned API-call will not remove anything if the paragraph is the only one of the object. It doesn't throw an error, though.
What I told about your suggestion concerning styles and layout is valid anyway.

Lupp gravatar imageLupp ( 2020-12-31 11:23:56 +0100 )edit

"Exclusively" @LeroyG:
I don't think this is a very relevant request, but it was a challenging example concerning my attempts to learn better how LibreOffice (and in specific the AP) works. Therefore I spent a few hours with it. Now I offer you personally the current state of my "remove-trailing-empty-paragraphs-project".
It's work in progress! (Though I don't know if I will continue it at any time. You are invited to solve the table-on-top-of-text issue, and to implement the current-selection-only variant.)
C:\fakepath\removeTrailingEmptyParagraphsNext.odt

Lupp gravatar imageLupp ( 2020-12-31 11:56:31 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-12-24 22:05:46 +0100

Seen: 42 times

Last updated: Dec 30 '20