OO-Snippets: add date to footer

Commons

Keywordsfooter, date, time, add date to footer, add time to footer
LanguageooRexx
ApplicationWriter
AuthorsNicole Scholz
Supported Versions2.0.x  
Supported OS
QuestionHow can I add the date and time to the footer?
Answer

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.

Code-Snippet-Listing (snippet-source)

/* 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~XDesktop~XComponentLoader  -- get componentLoader interface
/* open the blank file */
url = "private:factory/swriter"
xWriterComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0, .UNO~noProps)

xDocumentFactory = xWriterComponent~XMultiServiceFactory
xWriterDocument = xWriterComponent~XTextDocument
xText = xWriterDocument~getText()
xTextCursor = xText~createTextCursor()
xPropertySet = xTextCursor~xPropertySet
xDMsf = xWriterDocument~XMultiServiceFactory

  -- create the footer
xPageStyle = xDMsf~createInstance("com.sun.star.style.PageStyle")
xFamiliesSupplier = xWriterDocument~XStyleFamiliesSupplier
xStyle = xFamiliesSupplier~getStyleFamilies~getByName("PageStyles")~XNameContainer
xFooter = xStyle~getByName("Standard")
FooterProperty = xFooter~xPropertySet
FooterProperty~setPropertyValue("FooterIsOn", box("boolean", .true))
footerText = FooterProperty~getPropertyValue("FooterText")~xText

  -- Create the current date
datetime = xDMsf~createInstance("com.sun.star.text.TextField.DateTime")
datetimeProps = datetime ~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~XTextContent()
  -- Create the current time
datetime1 = xDMsf~createInstance("com.sun.star.text.TextField.DateTime")
datetimeProps1 = datetime1 ~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~XTextContent()

  -- create a line
xTextCursorFooter = footerText~createTextCursor
Line = xDMsf~createInstance("com.sun.star.drawing.LineShape")~xShape
Line~setPosition(.bsf~new("com.sun.star.awt.Point", 1, 1))
Line~setSize(.bsf~new("com.sun.star.awt.Size", 17000, 0))
xTextContentShape = Line~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

Changelog

DateUserModification

and