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

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
sevem
Posts: 2
Joined: Sat Sep 07, 2013 11:13 pm

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

Post by sevem »

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

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

      <style:header>
        <text:p>File: 
        <text:span text:style-name="MT1">
          <text:file-name text:display="name-and-extension">
          ???</text:file-name>
        </text:span>/ Page: 
        <text:sheet-name>???</text:sheet-name></text:p>
      </style:header>
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
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply