add remove header footer Josef Frysak How to toggle header and footer on and off?

First get the style name of the current Page. Next get the StyleFamilies

list of the document via the StyleFamiliesSupplier and retrieve the page

style with the name recieved before. Now get the "XPropertySet" interface

and retrieve the status of the header and footer. If they are true then

set their properties to false, otherwhise set them to true.

For further details see http://wi.wu-wien.ac.at/rgf/diplomarbeiten/BakkStuff/2008/200809_Frysak/200809_Frysak_Automating_OOo_ooRexx_Nutshells.pdf.

-- try to get a script context, will be .nil, if script was not invoked by OOo x_ScriptContext = uno.getScriptContext() if (x_ScriptContext <> .nil) then do -- invoked by OOo as a macro -- get context x_ComponentContext = x_ScriptContext~getComponentContext -- get desktop (an XDesktop) x_Desktop = x_ScriptContext~getDesktop -- get current document x_Document = x_ScriptContext~getDocument end else do -- called from outside of OOo, create a connection -- connect to Open Office and get component context x_ComponentContext = UNO.connect() -- create a desktop service and its interface service = "{%see com.sun.star.frame.Desktop}" s_Desktop = x_ComponentContext~getServiceManager~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory}~createInstance(service) x_Desktop = s_Desktop~{%see com.sun.star.frame.XDesktop%XDesktop} -- get the last active document x_Document = x_Desktop~getCurrentComponent() end -- first we get access to the textdocument and its text object x_TextDocument = x_Document~{%see com.sun.star.text.XTextDocument%XTextDocument} x_Text = x_TextDocument~getText -- get the current current cursor s_CurrentController = x_TextDocument~getCurrentController() x_TextViewCursorSupplier = s_CurrentController~{%see com.sun.star.text.XTextViewCursorSupplier%XTextViewCursorSupplier} x_CurrentCursor = x_TextViewCursorSupplier~getViewCursor() -- get access to the properties of the current cursor and retrieve -- name of the current pagestyle cursorproperties = x_CurrentCursor~{%see com.sun.star.beans.XPropertySet%XPropertySet} pagestylename = cursorproperties~getPropertyValue("PageStyleName") -- next we search the StyleFamily entries for our current pagestyle x_StyleFamiliesSupplier = x_Document~{%see com.sun.star.style.XStyleFamiliesSupplier%XStyleFamiliesSupplier} x_StyleFamilies = x_StyleFamiliesSupplier~getStyleFamilies() s_StyleFamily = x_StyleFamilies~getByName("PageStyles") x_NameAccess = s_StyleFamily~{%see com.sun.star.container.XNameAccess%XNameAccess} s_PageProperties = x_NameAccess~getByName(pagestylename) -- get the properties of the current page pageproperties = s_PageProperties~{%see com.sun.star.beans.XPropertySet%XPropertySet} -- get the current status of header and footer of this page oldheader = pageproperties~getPropertyValue("HeaderIsOn") oldfooter = pageproperties~getPropertyValue("FooterIsOn") -- if header is on turn it of and vice versa -- i dont know why disabling needs a complet object as parameter, but -- enabling does not. (enabling wont work if using objects) if oldheader then pageproperties~setPropertyValue("HeaderIsOn", .bsf~new("java.lang.Boolean", 0)) else pageproperties~setPropertyValue("HeaderIsOn", 1) if oldfooter then pageproperties~setPropertyValue("FooterIsOn", .bsf~new("java.lang.Boolean", 0)) else pageproperties~setPropertyValue("FooterIsOn", 1) ::requires UNO.CLS
Initial version