In this example the creation date and time are added to the footer.
They are set constant so they do not change when the document is opend again.
Also a line is added to the footer.
/* insert the date into the footer*/
/* Retrieve the Desktop object, we need its XComponentLoader interface to load a new document*/
oDesktop = UNO.createDesktop() -- get the UNO Desktop service object
xComponentLoader = oDesktop~{%see com.sun.star.frame.XDesktop%XDesktop}~{%see com.sun.star.frame.XComponentLoader%XComponentLoader} -- get componentLoader interface
/* open the blank file */
url = "private:factory/swriter"
xWriterComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0, .UNO~noProps)
xDocumentFactory = xWriterComponent~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory}
xWriterDocument = xWriterComponent~{%see com.sun.star.text.XTextDocument%XTextDocument}
xText = xWriterDocument~getText()
xTextCursor = xText~createTextCursor()
xPropertySet = xTextCursor~{%see com.sun.star.beans.XPropertySet%xPropertySet}
xDMsf = xWriterDocument~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory}
-- create the footer
xPageStyle = xDMsf~createInstance("{%see com.sun.star.style.PageStyle}")
xFamiliesSupplier = xWriterDocument~{%see com.sun.star.style.XStyleFamiliesSupplier%XStyleFamiliesSupplier}
xStyle = xFamiliesSupplier~getStyleFamilies~getByName("PageStyles")~{%see com.sun.star.container.XNameContainer%XNameContainer}
xFooter = xStyle~getByName("Standard")
FooterProperty = xFooter~{%see com.sun.star.beans.XPropertySet%xPropertySet}
FooterProperty~setPropertyValue("FooterIsOn", box("boolean", .true))
footerText = FooterProperty~getPropertyValue("FooterText")~{%see com.sun.star.text.XText%xText}
-- Create the current date
datetime = xDMsf~createInstance("{%see com.sun.star.text.TextField.DateTime}")
datetimeProps = datetime ~{%see com.sun.star.beans.XPropertySet%XPropertySet}()
datetimeProps~setPropertyValue("IsDate", box("boolean",.true))
-- set the date constant so it does not change when the document is opend
datetimeProps~setPropertyValue("IsFixed", box("boolean",.true))
datetimeTC = datetime~{%see com.sun.star.text.XTextContent%XTextContent}()
-- Create the current time
datetime1 = xDMsf~createInstance("{%see com.sun.star.text.TextField.DateTime}")
datetimeProps1 = datetime1 ~{%see com.sun.star.beans.XPropertySet%XPropertySet}()
datetimeProps1~setPropertyValue("IsDate", box("boolean",.false))
-- set the time constant so it does not change when the document is opend
datetimeProps1~setPropertyValue("IsFixed", box("boolean",.true))
datetimeTC1 = datetime1~{%see com.sun.star.text.XTextContent%XTextContent}()
-- create a line
xTextCursorFooter = footerText~createTextCursor
Line = xDMsf~createInstance("{%see com.sun.star.drawing.LineShape}")~{%see com.sun.star.drawing.XShape%xShape}
Line~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", 1, 1))
Line~setSize(.bsf~new("{%see com.sun.star.awt.Size}", 17000, 0))
xTextContentShape = Line~{%see com.sun.star.text.XTextContent%xTextContent}
-- insert the line at the top of the footer
footerText~insertTextContent(footerText, xTextContentShape, .false)
-- insert date and time to the footer
footerText~getEnd~setString(" date: ")
footerText~insertTextContent(footerText~getEnd, datetimeTC, .false)
footerText~getEnd~setString(" time: ")
footerText~insertTextContent(footerText~getEnd, datetimeTC1, .false)
::requires UNO.cls