[Solved] Enable print headers in Calc

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
MrLumme
Posts: 4
Joined: Mon Jul 10, 2017 3:10 pm

[Solved] Enable print headers in Calc

Post by MrLumme »

Hi.

I am trying to enable printing of row and column headers in Calc (OpenOffice 4.1.3, win10) with a macro, that runs when printing.
The macro I have written does not throw any errors, and when I ask it to output the value of the printHeaders option, the output is correct.
However the printout does not have the headers and when looking in Format > Page... > Print, printing of headers is not on.

This is my macro as of now;

Code: Select all

sub PrintRowLineNumbers

dim document as object
dim styleFamilies as Object
dim pageStyles as Object
dim defPage as Object

document = thisComponent
styleFamilies = document.styleFamilies
pageStyles = styleFamilies.getByName("PageStyles")
defPage = pageStyles.getByName("Default")
defPage.PrintHeaders  = 1

end sub
Does the macro need to refresh the document before it is updated? Or is it something else like that?
Any help will be greatly appreciated.

Note: The reason why I want to use a macro for this is because it needs to be done on a lot of files, and my attempts to unpack the files programmatically and edit the xmls inside have been unsuccessful as I can not pack them again without them being corrupted.
Last edited by MrLumme on Tue Jul 11, 2017 4:48 pm, edited 2 times in total.
OpenOffice 4.1.3, win7 & win10
User avatar
Zizi64
Volunteer
Posts: 11358
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Enable print headers in Calc

Post by Zizi64 »

Does your document have the default page style only? (Is there applied the default page style only for the sheets?)
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.
MrLumme
Posts: 4
Joined: Mon Jul 10, 2017 3:10 pm

Re: Enable print headers in Calc

Post by MrLumme »

Okay, I tried to make a new document to test with and it works.

So I would guess the reason before is exactly what you are calling out.
I unsure of what style they are in, but I'll assume that even if most are default there might to some that have special styles in-between.

Do you know if it is possible to force enable header no matter what style(s) are used? Or if a macro can list all the used styles?
OpenOffice 4.1.3, win7 & win10
FJCC
Moderator
Posts: 9270
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Enable print headers in Calc

Post by FJCC »

You can loop through all of the page styles like this

Code: Select all

sub PrintRowLineNumbers

dim document as object
dim styleFamilies as Object
dim pageStyles as Object
dim defPage as Object

document = thisComponent
styleFamilies = document.styleFamilies
pageStyles = styleFamilies.getByName("PageStyles")
Count = pageStyles.Count
for i = 0 to Count - 1
  PageStyle = pageStyles.getByIndex(i)
  PageStyle.PrintHeaders  = 1
next i
end sub
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
MrLumme
Posts: 4
Joined: Mon Jul 10, 2017 3:10 pm

Re: Enable print headers in Calc

Post by MrLumme »

It works! Thank you very much, you have saved my day :D
OpenOffice 4.1.3, win7 & win10
Post Reply