When I run the following Macro in sCalc, the lines in bold give an error :
Basic runtime error
Property or Method not found.
Code: Select all
Sub AddHeader(optional doc)
oDoc = IIf(IsMissing(doc), ThisComponent, doc)
' turn on headers for default page style
oStyle = oDoc.StyleFamilies.getByName("PageStyles").getByName("Default")
oStyle.HeaderIsOn = True
oStyle.HeaderIsShared = True
oStyle.HeaderHeight = 500 ' 0.5 cm - header height
oStyle.HeaderBodyDistance = 0 ' 0 cm - distance from page text area to header
' decrease the top margin by 0.5 cm (the header's height)
oPageStyle = oDoc.StyleFamilies.getByName("PageStyles").getByName("Default")
oPageStyle.TopMargin = oPageStyle.TopMargin - 500
' Add some regular text. In OpenOffice.org 1.1, newly created headers have a centered
' tabstop at the center of header area and a right tab stop at the right margin.
' In OO 1.0, one would have to set tabstops in the macro,
' otherwise default tab stops of 1,25 cm would be used. Tab is Chr(09).
[b]oStyle.HeaderText.SetString("MyCompany header text - left" & Chr(09) _
& "centered text")[/b] ' add some fields
oCursor = oStyle.HeaderText.createTextCursor()
oCursor.GotoEnd(false)
oStyle.HeaderText.insertString(oCursor, Chr(09) & "Page ", false)
' insert "page number" field
oField = oDoc.createInstance("com.sun.star.text.TextField.PageNumber")
oField.NumberingType = 4 ' magic constant: 4=Arabic numbers
oField.SubType = 1 ' another magic constant (use current page number)
oStyle.HeaderText.insertTextContent(oCursor, oField, False)
' more regular text
oStyle.HeaderText.insertString(oCursor, " of ", false)
' insert "total pages" field
oField = oDoc.createInstance("com.sun.star.text.TextField.PageCount")
oField.NumberingType = 4 ' as above
oStyle.HeaderText.insertTextContent(oCursor, oField, False)
' Now set some formatting (reuse cursor object)
oCursor.gotoStart(false)
oCursor.gotoEnd(true)
oCursor.CharHeight = "6" ' font size
oCursor.CharFontName = "Times New Roman" ' font name
' set text locale to "no locale" (empty locale object) in order to turn off
' any spell checking in the header
Dim aLocale As New com.sun.star.lang.Locale
' Uncomment the lines below to use a specific locale, e.g. US English, instead
' aLocale.Language = "en"
' aLocale.Country = "US"
oCursor.CharLocale = aLocale
End Sub
Abhay