[Solved] Calc: How to set Page Header in Basic?

Creating a macro - Writing a Script - Using the API

[Solved] Calc: How to set Page Header in Basic?

Postby sevem » Tue Sep 24, 2013 11:03 pm

For setting the page header in Calc I use the following menu commands:
  • Format -> Page... -> Header -> Edit...
  • For "Center Area" I insert following string (with fields <File Name> and <Sheet Name>):
  • File: <File Name> / Page: <Sheet Name>
  • The file name I set to be in bold and the rest of the text is regular text.
This setting I would like to do in a Basic macro. Using MRI I came to the point, where the header information is stored, but could not find the exact properties to set. The following sequence in MRI brings me to the string for the page header. What I am missing now is the place where to set the properties and the place where to define the string formatting (bold text).

Code: Select all   Expand viewCollapse view
Sub Snippet
  Dim oStyleFamilies As Variant
  Dim oObj1 As Variant
  Dim oObj2 As Variant
  Dim oRightPageHeaderContent As Variant
  Dim oCenterText As Variant
  Dim sString As String
  Dim oTextFields As Variant
  Dim nCount As Long

  oStyleFamilies = ThisComponent.getStyleFamilies()
  oObj1 = oStyleFamilies.getByName("PageStyles")
  oObj2 = oObj1.getByName("Default")
  oRightPageHeaderContent = oObj2.RightPageHeaderContent
  oCenterText = oRightPageHeaderContent.getCenterText()
  sString = oCenterText.getString() ' --> "File: ??? / Page: ???" (string used in the header with placeholders for the fields)
  oTextFields = oCenterText.getTextFields()
  nCount = oTextFields.getCount() ' --> "2" (number of fields used in the string)
End Sub

In trying to find the correct properties I looked into the file "styles.xml" that is part of the stored document. I found the definition of the header but it did not help me further. Below the snippet of this file describing the header.

Code: Select all   Expand viewCollapse view
        <text:span text:style-name="MT1">
          <text:file-name text:display="name-and-extension">
        </text:span>/ Page:

Thanks for any hint to find a solution.
Last edited by sevem on Fri Sep 27, 2013 11:45 am, edited 1 time in total.
OpenOffice 4 on Windows 7
Posts: 2
Joined: Sat Sep 07, 2013 11:13 pm

Re: Calc: How to set Page Header in Basic?

Postby Villeroy » Wed Sep 25, 2013 12:27 am

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.4
User avatar
Posts: 28353
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 3 guests