Find & Replace the last empty paragraph in a table cell

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.

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

For me, this deletes all end of paragraphs.

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,

all end of paragraphs.

Not the same that empty paragraphs.

“user code” ≈ macro?

@EarnestAl and @Lupp, Thanks for the support!

These tables contains only plain text, so styles was no important.

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

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.

1 Like

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.

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.

“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.)
removeTrailingEmptyParagraphsNext.odt