[Solved] Accessing page header/footer of Writer docs
[Solved] Accessing page header/footer of Writer docs
Hello, is it possible to access the content (e.g. its paragraphs) of the header and footer of each page of a loaded document in Writer?
I found the HeaderFooterContent service but I’m not quite sure how to get from the loaded TextDocument to its page headers/footers…
I’ll keep poking and MRI’ing around, but would appreciate if somebody would be able to point me into the right direction…
Much thanks!
Jens
I found the HeaderFooterContent service but I’m not quite sure how to get from the loaded TextDocument to its page headers/footers…
I’ll keep poking and MRI’ing around, but would appreciate if somebody would be able to point me into the right direction…
Much thanks!
Jens
Last edited by _savage on Wed May 11, 2022 11:55 am, edited 2 times in total.
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
Re: Programmatically accessing page header/footer of Writer
Assuming there is a header its text is part of the page style.
Code: Select all
mri thiscomponent.stylefamilies.getbyname("PageStyles")
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Programmatically accessing page header/footer of Writer
Thanks JeJe! I think I found it…JeJe wrote:Assuming there is a header its text is part of the page style.
So, the 'PageStyles' provides a StyleFamily service to access styles for 'Standard', 'First Page', 'Left Page', 'Right Page', … which each provide the PageProperties service, which in turn has the HeaderBla and FooterBla properties for these page styles. I think that’s what I was looking for
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
Re: Accessing page header/footer of Writer docs
Hmm Is it possible that a header/foot is protected against modification?
I can iterate over the TextRange objects in the header’s/footer’s paragraph, but when I call setString() on any one range it has no effect? Interestingly, if I call getString() on the owning paragraph then that string contains the modification — it’s just not displayed in the document or saved (screenshot shows MRI editing the component):
I can iterate over the TextRange objects in the header’s/footer’s paragraph, but when I call setString() on any one range it has no effect? Interestingly, if I call getString() on the owning paragraph then that string contains the modification — it’s just not displayed in the document or saved (screenshot shows MRI editing the component):
Last edited by _savage on Thu May 12, 2022 11:51 am, edited 1 time in total.
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
Re: Accessing page header/footer of Writer docs
Works for me,
Code: Select all
txt= thiscomponent.stylefamilies.getbyname("PageStyles").getbyindex(0).headertext
txt.setstring "whatever"
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Accessing page header/footer of Writer docs
Yes the change is saved. Testing on LO on Windows 8
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Accessing page header/footer of Writer docs
Which LO version are you on, and is that an ODT or DOCX? I wonder if I have a funky DOCX version…
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
Re: Accessing page header/footer of Writer docs
7.2.2.2 Works for me saving in both.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)