Apache OpenOffice 4.1.14
When using FindCreateNumberFormatStyle for setting a date in a footer in CALKC, I get an error : "Sub-procedure or function not defined"
The script is a slight variant of the script from Andrew Pitonyak (https://pitonyak.org/AndrewMacro.pdf, section 6.17)
I am using this script in a calc document as a template (.OTS)
Code: Select all
Sub Main
GlobalScope.BasicLibraries.LoadLibrary("Tools") ' loading Tools library
SetFooterDateInSpreadSheet ()
End Sub
Sub SetFooterDateInSpreadSheet
Dim oDoc, oSheet, oPstyle, oHeader, oFooter
Dim oText, oCursor, oField
Dim oStyles
Dim sService$
Dim ODateTime
oDoc = ThisComponent
' Get the pagestyle for the currently active sheet.
oSheet = oDoc.CurrentController.getActiveSheet
oStyles = oDoc.StyleFamilies.getByName("PageStyles")
oPstyle = oStyles.getByName(oSheet.PageStyle)
' Turn headers on and then make them shared!
oPstyle.FooterOn = True
oPstyle.FooterShared = True
' The is also a RightText and a LeftText
oFooter = oPstyle.RightPageFooterContent
oText = oFooter.RightText
' You may now set the text object to be anything you desire
' Use setSTring() from the text object to set simple text.
' Use a cursor to insert a field (such as the current sheet name).
' First, clear any existing text!
oText.setString("")
s = "com.sun.star.text.TextField.DateTime"
ODateTime = oDoc.createInstance(s)
oDateTime.IsFixed = TRUE
oDateTime.NumberFormat = FindCreateNumberFormatStyle("DD. MMMM YYYY", oDoc)
oText.insertTextContent(oTCurs,oDateTime,FALSE)
oText.insertString(oTCurs," ",FALSE)
oCursor = oText.createTextCursor()
'--- oText.insertString(oCursor, "Sheet: ", False)
' This will have the sheet name of the current sheet!
' sService = "com.sun.star.text.TextField.SheetName"
'--- sService = "com.sun.star.text.TextField.SheetName"
' oField = oDoc.createInstance(sService)
' oText.insertTextContent(oCursor, oField, False)
' And now for the part that holds the entire thing together,
' You must write the header object back because we have been
' modifying a temporary object
oPstyle.RightPageFooterContent = oFooter
End Sub
advTHANKSance