Insert Header and Footer content in Excel (E)

Modified on Mon, 5 Oct at 1:54 PM

Excel worksheets each contain three areas in the header and three areas in the footer which can be populated as needed. Base Extensions can be used to add/remove content directly into these areas. As well as inserting plain text it can be used in conjunction with the codes provided by Microsoft to allow references to be included, and define formatting etc. More details on this can be found here:

https://docs.microsoft.com/en-us/office/vba/excel/concepts/workbooks-and-worksheets/formatting-and-vba-codes-for-headers-and-footers

It is also possible to format the headers and footers using VBA formatting. This should be done by inserting the formatting code in a <![CDATA[&L&12]]> element. Make sure that you use the alignment corresponding to the section the data is inserted in (i.e. left alignment in left section etc.).

It is important to note that there can only be added one formatting per header/footer section (left, center, or right). This is due to an Excel bug where mutliple formattings will show the inserted data as overlapping until the header/footer section is manually activated. See below image for example:

CMD

<Cmd case="BaseExtensions:xl-header-footer-text"/>

Parameters

All Parameters are optional.

AllSheets

Accepts true or false (default) as value. Selecting true will insert any defined text in all worksheets within the workbook.

LeftHeader

Defines the text to be displayed in the left hand side of the header. Omitting will leave that area blank.

CenterHeader

Defines the text to be displayed in the center of the header. Omitting will leave that area blank.

RightHeader

Defines the text to be displayed in the right hand side of the header. Omitting will leave that area blank.

LeftFooter

Defines the text to be displayed in the left hand side of the footer. Omitting will leave that area blank.

CenterFooter

Defines the text to be displayed in the center of the footer. Omitting will leave that area blank.

RightFooter

Defines the text to be displayed in the right hand side of the footer. Omitting will leave that area blank.

Example:

XML
 <Cmd case="BaseExtensions:xl-header-footer-text"
AllSheets="true"
LeftFooter="&amp;Z&#xD;&amp;F : &amp;A&#xD;© Omnidocs | F0.13 | 14 February 2011"
RightFooter="Page &amp;P of &amp;N&#xD;Printed &amp;D Time &amp;T"
/>

This results in a footer applied to all worksheets that looks like:
mceclip1.png

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article