# 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… 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 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

( 2020-12-25 07:21:09 +0100 )edit

For me, this deletes all end of paragraphs.

( 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. ( 2020-12-25 15:14:11 +0100 )edit all end of paragraphs. Not the same that empty paragraphs. "user code" ≈ macro? ( 2020-12-25 15:52:03 +0100 )edit @Earnest Al and @Lupp, Thanks for the support! ( 2020-12-25 16:05:46 +0100 )edit ## 1 Answer Sort by » oldest newest most voted 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.

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

more

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.

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

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

( 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

( 2020-12-31 11:56:31 +0100 )edit