[Solved] Remove empty lines between tables

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Mr.Dandy
Posts: 427
Joined: Tue Dec 11, 2012 4:22 pm

[Solved] Remove empty lines between tables

Post by Mr.Dandy »

Hello,

I'm try to use this regex

Code: Select all

^$
But nothing is found
Attachments
0-sample-regex.odt
(8.95 KiB) Downloaded 60 times
Last edited by Mr.Dandy on Sat Feb 17, 2024 6:22 pm, edited 1 time in total.
OpenOffice 4.1.12 - Windows 10
erbsenzahl
Volunteer
Posts: 255
Joined: Tue Apr 18, 2017 8:23 am
Location: Germany

Re: Remove empty lines between tables

Post by erbsenzahl »

It seems that there is a special connection of tables and their trailing paragraphs.

EDIT
You can manually delete the trailing paragraphs (DEL key or in the last table cell shortcut CTRL+SHIFT+DEL) but not the trailing paragraph of the (stand alone) last table.
To delete the trailing paragraph of the last stand alone paragraph you can work on OpenOffice 3.x, but after saving/closing and opening again it will be automatically generated again...
Last edited by erbsenzahl on Tue Feb 13, 2024 11:26 am, edited 2 times in total.
LibreOffice current versions 7 and OpenOffice 4.1.15
on LinuxMint 20 - 21 Mate, W10-64 pro
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Remove empty lines between tables

Post by RoryOF »

From memory every table has a trailing line, which cannot be removed. I think it can however be selected and reduced to 2 points, the minimum allowed in this case.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Remove empty lines between tables

Post by RoryOF »

erbenzahl is correct: experiment shows one can manually delete each inter table paragraph mark, but not the final one; that however can be reduced to two points.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Remove empty lines between tables

Post by JeJe »

You can put the tables in frames and align them together or even overlap them.
Attachments
tabels in frames.odt
(9.5 KiB) Downloaded 49 times
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Hagar Delest
Moderator
Posts: 32668
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Remove empty lines between tables

Post by Hagar Delest »

Actually, there is a trick to "remove" the last paragraph below a table: type at least a character (can be a space, or better a string like "last line") and set the character properties of that "paragraph" to hidden.
:ugeek:

Please add [Solved] at the beginning of the title in your first post (top of the topic) with the 🖉 button if your issue has been fixed.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
MrProgrammer
Moderator
Posts: 4909
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Remove empty lines between tables

Post by MrProgrammer »

RoryOF wrote: Tue Feb 13, 2024 11:16 am From memory every table has a trailing line, which cannot be removed.
Yes, a table must be contained in a paragraph, and every paragraph requires a paragraph properties marker (the ¶) at the end. If the table is the last element in the paragraph, the marker must be placed after the table because it is not possible to place content left or right of a table. However one can prevent the paragraph marker after the table from being displayed on the page. Several suggestions are in the replies above.

Mr.Dandy wrote: Tue Feb 13, 2024 10:19 amRemove empty lines between tables
To avoid space between tables:
• You can put multiple tables in the same paragraph (put cursor before paragraph's ¶ and use Insert → Table)
• You can put multiple-subtables in a paragraph consisting of a 1-row 1-column table
202402131011.odt
(11.71 KiB) Downloaded 54 times

Using the latter method you can copy/paste the text of your attachment into the 1-row 1-column table and then remove the paragraph markers that you don't want so the tables don't have space between them. The 1-row 1-column table must be contained in a paragraph, but the sub-tables inside don't require paragraph markers because their paragraph is the one with the outer table. I will admit that sub-tables can be confusing and may be difficult to work with.

Here is earlier discussion about the empty line after a table.
[Solved] Undeletable page when filling whole page with table

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Remove empty lines between tables

Post by JeJe »

So using MrProgrammer's method:

select the table and do a copy
delete the table
On the paragraph below the previous table use Table menu/insert table of the same size
paste what was copied from the old table into the new one.

*

A slight variation on Hagar Delest's method would be to create a paragraph style with the hidden font effect property then that style can be applied to the line without any text being needed. And it can be reversed easily to put the lines back by removing the hidden font effect from the style.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Hagar Delest
Moderator
Posts: 32668
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Remove empty lines between tables

Post by Hagar Delest »

JeJe wrote: Wed Feb 14, 2024 12:18 pm A slight variation on Hagar Delest's method would be to create a paragraph style with the hidden font effect property then that style can be applied to the line without any text being needed. And it can be reversed easily to put the lines back by removing the hidden font effect from the style.
The best method in the end IMHO. Because you can display again those lines very easily by accessing that custom paragraph style from the Stylist, no need to play with the display options to make the hidden characters visible.
I'm not sure it was possible to set the hidden settings to a paragraph style in the past.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
Mr.Dandy
Posts: 427
Joined: Tue Dec 11, 2012 4:22 pm

Re: Remove empty lines between tables

Post by Mr.Dandy »

As I said in my first post, I would like to remove only empty lines between two tables
Expected result below:
capture.gif
capture.gif (3.55 KiB) Viewed 1674 times


This can be done manually.
But my document is of course more complex than the one shown as example.
 Edit: Moved from Writer forum to Macros and UNO API because Mr.Dandy wants a macro. -- MrProgrammer, forum moderator  
Last edited by MrProgrammer on Thu Feb 22, 2024 3:47 am, edited 1 time in total.
Reason: Move topic to Macros and UNO API
OpenOffice 4.1.12 - Windows 10
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Remove empty lines between tables

Post by RoryOF »

Why does it arise that you wish to compact several tables? Why not make one longer table to contain all the information?
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Hagar Delest
Moderator
Posts: 32668
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Remove empty lines between tables

Post by Hagar Delest »

Mr.Dandy wrote: Wed Feb 14, 2024 3:16 pm But my document is of course more complex than the one shown as example.
Actually, that would have been useful in the first post.
Now what I understand is that you have a possibly long document with lots of tables, that may have different layouts, and you want to remove the empty paragraphs between them at once. Since they already exist, having a single table in the first place is not the point.

You can try the AltSearch extension, it may fond those empty paragraph between tables.
Else, the only way I see is to make a macro with a cursor that goes to a table, then to its last cell, then go right to go to the next paragraph then select the paragraph, if null, then delete, then go to the next table (if cursor is not in the next table already).
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Remove empty lines between tables

Post by RoryOF »

If one is editing an existing document, then the table compaction makes sense. However, it may be difficult to label each of the component tables when they are all close together. Typically, each table in a document is given a unique name for reference from the accompanying text.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Remove empty lines between tables

Post by JeJe »

This works on your sample file. It removes the blank line if there is one following every table provided that line isn't itself in a table. If there are tables with blank lines following tables that you don't want to remove you'll need to adapt the code for that.

Code: Select all

Sub RemoveLines

for i = 0 to thiscomponent.texttables.getcount -1
t = thiscomponent.texttables.getbyindex(i)
tc= t.getanchor.text.createtextcursorbyrange( t.getanchor.end)
tc.goright 1,false
if isempty(tc.texttable ) then
with tc.createenumeration.nextelement
if .string = "" then .dispose
end with
end if
next

End Sub
Edit: oops didn't add test to see if paragraph following table was empty - corrected.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Mr.Dandy
Posts: 427
Joined: Tue Dec 11, 2012 4:22 pm

Re: Remove empty lines between tables

Post by Mr.Dandy »

The macro works fine. Thanks
That's solved the regex issue.
OpenOffice 4.1.12 - Windows 10
Post Reply