Page m of n in footer reverts to default style

Creating a macro - Writing a Script - Using the API

Page m of n in footer reverts to default style

Postby Grytpype » Tue Mar 05, 2019 7:14 pm

I've just had LibreOffice upgraded, and a macro no longer works quite right. As part of reformatting a document it puts "Page m of n" in small print in the footer. It still does this, but now only the word "Page" appears in the small print, while the " of " and the two variable numbers have reverted to the default font and size. The relevant code is:
Code: Select all   Expand viewCollapse view
FTR_FONT = "Calibri"
FTR_SIZE = 8
' Short names for stupidly named things
kARABIC = com.sun.star.style.NumberingType.ARABIC
kPAGENO = "com.sun.star.text.textfield.PageNumber"
kPAGECT = "com.sun.star.text.textfield.PageCount"
' . . .
cur4 = style.footertext.text.createtextcursor
cur4.charfontname = FTR_FONT
cur4.charheight = FTR_SIZE
' . . .
pageno = doc.createinstance(kPAGENO)
pageno.numberingtype = kARABIC ' default is A, B, C ...!
pageno.subtype = 1 ' subtype 1 = use current page no.
pagect = doc.createinstance(kPAGECT)
pagect.numberingtype = kARABIC
style.footertext.text.insertstring(cur4, chr(9) & "page ", 0) ' 9 = tab
style.footertext.text.inserttextcontent(cur4, pageno, 0)
style.footertext.text.insertstring(cur4, " of ", 0)
style.footertext.text.inserttextcontent(cur4, pagect, 0)

The four text inserts are consecutive, as you see. Why has it changed format after the first one?

Edited: Didn't notice pageno and pagect were my own variable names, so I've added their definitions.
LibreOffice 6.2.0.3 on Windows 10 Pro, as of March 2019: just upgraded from 4.1.6.2
Grytpype
 
Posts: 11
Joined: Mon Apr 14, 2014 5:26 pm
Location: London

Re: Page m of n in footer reverts to default style

Postby JeJe » Tue Mar 05, 2019 9:39 pm

Have you tried putting

cur4.charfontname = FTR_FONT
cur4.charheight = FTR_SIZE

again after every insert?
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 551
Joined: Wed Mar 09, 2016 2:40 pm

Re: Page m of n in footer reverts to default style

Postby Grytpype » Wed Mar 06, 2019 2:52 pm

Okay, I've now tried that. Actually I put it in front of the second insert (of pageno) and it made that correct and the following "of", but the second variable field was still wrong. So it's the variables that are reverting to the default.

When I looked up how to do the equivalent in MS Word, namely .Fields.Add() with Text of "PAGE" or "NUMPAGES", I saw the example code always included PreserveFormatting:=True. This sounds like exactly what is needed, but in fact it works fine in Word if you leave that out. Is there an equivalent parameter that has been recently added to LO, perhaps?

I have just been warned (on another thread) that my newly installed version is buggy, not stable, so perhaps this is just one of those things. Anyway, it's working now, with inelegantly repeated code.
LibreOffice 6.2.0.3 on Windows 10 Pro, as of March 2019: just upgraded from 4.1.6.2
Grytpype
 
Posts: 11
Joined: Mon Apr 14, 2014 5:26 pm
Location: London

Re: Page m of n in footer reverts to default style

Postby Villeroy » Wed Mar 06, 2019 2:57 pm

If you don't understand the concept of templates and styles, you can't use nor program this office suite. And once you know about styles and templates you don't need those dirty macros anymore.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 26967
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Page m of n in footer reverts to default style

Postby JeJe » Wed Mar 06, 2019 4:13 pm

Elegance is fine - but if you can hack together something else that acceptably works, then its a waste your time.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 551
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 2 guests