[Solved] Writer tables ParaKeepTogether not working

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
TeunD
Posts: 3
Joined: Tue Jul 05, 2022 1:46 pm

[Solved] Writer tables ParaKeepTogether not working

Post by TeunD »

I have a document with many (>100) small tables. On each page nearly two tables fit. But often a table is split over two pages. Manually easily solvable by clicking on a cell in the relevant table with a page break, and then: > Table > Table properties... > uncheck 'Allow table to split across pages and columns', or checking 'Keep with next paragraph'. Either one or the other will do the job.
But to repeat this >100 time for all tables, I thought it might be faster to do it in a script.
First I record a macro while I am doing it manually. Then OO spits out something like:

Code: Select all

sub TableNoBreak
 dim document   as object
 dim dispatcher as object
 document   = ThisComponent.CurrentController.Frame
 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
 dim args1(0) as new com.sun.star.beans.PropertyValue
 args1(0).Name = "ParaKeepTogether"
 args1(0).Value = true
 dispatcher.executeDispatch(document, ".uno:ParaKeepTogether", "", 0, args1())
 end sub
In case of the other option, ParaKeepTogether is replaced by RowSplit (set to false instead of the default true).

Now I select manually a cell in another table with a page break, and I execute this recorded macro, and then ... nothing happens, page breaks are still in the tables.

Before this, after installation of OO, I already did: Tools > Options... > OpenOffice > Security > Macro security... > Low
I didn't install JRE, isn't needed to run Basic macros? OO didn't complain.
Can anybody please tell me what am I doing wrong ?
An example file (with recorded macro) is attached.
Attachments
TableBreakExample.odt
(12.68 KiB) Downloaded 97 times
Last edited by Hagar Delest on Wed Jul 06, 2022 8:01 am, edited 1 time in total.
OpenOffice 4.1.12 on Windows 10
ms777
Volunteer
Posts: 177
Joined: Mon Oct 08, 2007 1:33 am

Re: swriter tables ParaKeepTogether not working from macro

Post by ms777 »

Code: Select all

Sub Main
oDoc = ThisComponent
for i=0 to oDoc.TextTables.Count-1
	oTable = oDoc.TextTables.getByIndex(i)
	oTable.Split = false
next i 
End Sub
Good luck,

ms777
TeunD
Posts: 3
Joined: Tue Jul 05, 2022 1:46 pm

Re: swriter tables ParaKeepTogether not working from macro

Post by TeunD »

Oh my dear, I am surprised, and ashamed. So simple,and its working perfect (and fast). Why does OO spit out uno commands, when it can also be done this way (and the uno commands don't even work)? Thank you, very much clarifying !
OpenOffice 4.1.12 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: swriter tables ParaKeepTogether not working from macro

Post by Zizi64 »

Why does OO spit out uno commands, when it can also be done this way (and the uno commands don't even work)?
Because you want to use it for a Table but not for pure text Paragraphs.

First I record a macro while I am doing it manually.
You need WRITE your macros based on the API functions - if you want to work with macros efficiently.
The Macro Recorder has a limited capability, and it works in the Calc and Writer applications only (but not in Impress, nor Draw...)
The API works in all of the applications.
API: Application Programming Interface.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
TeunD
Posts: 3
Joined: Tue Jul 05, 2022 1:46 pm

Re: [Solved] Writer tables ParaKeepTogether not working

Post by TeunD »

I couldn't find a working example on the internet how to do it with the UNO functions. Because I am working in Writer, I could use the macro recorder, and I thought it would tell me how to do it; mistake. But the code given by ms777 works perfectly. Googling on its key-words (OpenOffice writer macro Table Split false), I am finding many examples.
Someone already put [Solved] before the subject before I did it.
OpenOffice 4.1.12 on Windows 10
Post Reply