<?xml version="1.0"?>

<!--
$RCSfile: index.html,v $

last change: $Revision: $ $Author: $ $Date: $

(c)2003 by the copyright holders listed with the author-tags.
If no explicit copyright holder is mentioned with a certain author,
the author him-/herself is the copyright holder. All rights reserved.

Public Documentation License Notice:

The contents of this Documentation are subject to the
Public Documentation License Version 1.0 (the "License");
you may only use this Documentation if you comply with
the terms of this License. A copy of the License is
available at http://www.openoffice.org/licenses/PDL.html

The Original Documentation can be found in the CVS archives
of openoffice.org at the place specified by RCSfile: in this header.

The Initial Writer(s) of the Original Documentation are listed
with the author-tags below.

The Contributor(s) are listed with the author-tags below
without the marker for being an initial author.

All Rights Reserved.
-->

<snippet language="OOBasic" application="Calc">

<keywords>
	<keyword>header</keyword>
	<keyword>footer</keyword>
	<keyword>page number</keyword>
	<keyword>page count</keyword>
</keywords>

<authors>
	<author id="kohei" initial="true" email="kohei@openoffice.org" copyright="Kohei Yoshida">Kohei Yoshida</author>
</authors>

<question heading="Edit header and footer">
How do I edit the header and footer of a Calc document?
</question>

<answer>
<p>The header and footer of a Calc document can be accessed and modified from a page style object.  A page style object can be obtained from the document object as shown in the example code below.</p>
<p>In this example, the &quot;Default&quot; page style is used to modify the header and footer.  Also note that in a single-sided page document, only the right page header and footer are used, and the left page header and footer are ignored.  In a two-sided page document, on the other hand, both the left and right pages need to be edited accordingly.</p>
<p>Also, the header or footer object needs to be re-inserted after it has been modified, or the change will not take effect.</p>

<listing>
Sub setHeaderAndFooter

       oDoc = ThisComponent
       oStyles = oDoc.getStyleFamilies().getByName( &quot;PageStyles&quot; )
       oPStyle = oStyles.getByName( &quot;Default&quot; )
       
       &apos; Get page number and page count objects.
       oPageNumber = oDoc.createInstance( &quot;com.sun.star.text.TextField.PageNumber&quot; )
       oPageCount  = oDoc.createInstance( &quot;com.sun.star.text.TextField.PageCount&quot; )
       oDateTime   = oDoc.createInstance( &quot;com.sun.star.text.TextField.DateTime&quot; )
       
       &apos; Edit header
       oHeader = oPStyle.RightPageHeaderContent
       oHeader.getLeftText().setString( &quot;&quot; )
       oHeader.getCenterText().setString( &quot;ABC Company, Inc.&quot; )
       oCursor = oHeader.getRightText().createTextCursor()
       oHeader.getRightText().insertTextContent( oCursor, oDateTime, True )
       oPStyle.RightPageHeaderContent = oHeader
       
       &apos; Edit footer
       oFooter = oPStyle.RightPageFooterContent
       oFooter.getLeftText().setString( &quot;Monthly Report&quot; )
       oFooter.getCenterText().setString( &quot;&quot; )
       
       oFooter.getRightText().setString( &quot;Page &quot; )
       oCursor = oFooter.getRightText().createTextCursor()
       oCursor.gotoEnd( False )
       oFooter.getRightText().insertTextContent( oCursor, oPageNumber, True )
       oCursor.gotoEnd( False )
       oCursor.setString( &quot; of &quot; )
       oCursor.gotoEnd( False )
       oFooter.getRightText().insertTextContent( oCursor, oPageCount, True )
       oPStyle.RightPageFooterContent = oFooter

End Sub
</listing>
</answer>

<changelog>
</changelog>

</snippet>
