[Solved] Enable print headers in Calc

Creating a macro - Writing a Script - Using the API

[Solved] Enable print headers in Calc

Postby MrLumme » Tue Jul 11, 2017 2:25 pm

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   Expand viewCollapse view
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
MrLumme
 
Posts: 4
Joined: Mon Jul 10, 2017 3:10 pm

Re: Enable print headers in Calc

Postby Zizi64 » Tue Jul 11, 2017 3:59 pm

Does your document have the default page style only? (Is there applied the default page style only for the sheets?)
Tibor Kovacs, Hungary; LibreOffice4.4.7 on Win7x64Prof.
And the portable versions: LO3.3.0-LO5.3.4 and AOO4.1.3
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 5624
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Enable print headers in Calc

Postby MrLumme » Tue Jul 11, 2017 4:23 pm

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
MrLumme
 
Posts: 4
Joined: Mon Jul 10, 2017 3:10 pm

Re: Enable print headers in Calc

Postby FJCC » Tue Jul 11, 2017 4:28 pm

You can loop through all of the page styles like this
Code: Select all   Expand viewCollapse view
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
AOO 3.4 or 4.1 on MS Windows XP ( before 2013-08-03) or Windows 7
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 5954
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Enable print headers in Calc

Postby MrLumme » Tue Jul 11, 2017 4:47 pm

It works! Thank you very much, you have saved my day :D
OpenOffice 4.1.3, win7 & win10
MrLumme
 
Posts: 4
Joined: Mon Jul 10, 2017 3:10 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 9 guests