Page 1 of 1

[Solved] Enable print headers in Calc

Posted: Tue Jul 11, 2017 2:25 pm
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.

Re: Enable print headers in Calc

Posted: Tue Jul 11, 2017 3:59 pm
by Zizi64
Does your document have the default page style only? (Is there applied the default page style only for the sheets?)

Re: Enable print headers in Calc

Posted: Tue Jul 11, 2017 4:23 pm
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?

Re: Enable print headers in Calc

Posted: Tue Jul 11, 2017 4:28 pm
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

Re: Enable print headers in Calc

Posted: Tue Jul 11, 2017 4:47 pm
by MrLumme
It works! Thank you very much, you have saved my day :D