Forums     Knowledge Base     OfficeWriter Online     
 
 
This documentation is for
OfficeWriter v3.8.1
.NET Platform

View Docs for Another
Version or Platform

ExcelApplication in Depth > Formatting Headers and Footers

ExcelApplication is not
available in ExcelWriterSE.

Formatting Headers and Footers

The following properties of PageSetup allow you to create and format spreadsheet headers and footers:

  • CenterFooter
  • CenterHeader
  • LeftFooter
  • LeftHeader
  • RightFooter
  • RightHeader
  • HeaderMargin
  • FooterMargin

To see spreadsheet headers and footers in Excel, open the File menu, select Page Setup, and select the Header/Footer tab.

To format a header or footer in script, include formatting codes within the ExcelWriter header/footer property, for example:

using SoftArtisans.OfficeWriter.ExcelWriter;

public class HeaderFooterDemo : System.Web.UI.Page
{
	protected void Page_Load(object sender, System.EventArgs e)
	{
		ExcelApplication xla = new ExcelApplication();
		Workbook wb = xla.Create(); 
		Worksheet sheet1 = wb.Worksheets[0];
		PageSetup pgsetup = sheet1.PageSetup;
		pgsetup.LeftHeader = "Document name: &F";
		pgsetup.CenterHeader = "Basic Report";
		pgsetup.RightHeader = "Generated by OfficeWriter";
		pgsetup.LeftFooter = "Created on date &D";
		pgsetup.CenterFooter = "Page &P of &N";
		pgsetup.RightFooter = "Create at time &T";

		...
	}
}
Formatting Codes for Headers and Footers
&LLeft aligns the characters that follow.
&CCenters the characters that follow.
&RRight aligns the characters that follow.
&ETurns double-underline on or off.
&XTurns superscript on or off.
&YTurns subscript on or off.
&BTurns bold on or off.
&ITurns italic on or off.
&UTurns underline on or off.
&STurns strikethrough on or off.
&DPrints the current date.
&TPrints the current time.
&FPrints the name of the document.
&APrints the name of the worksheet.
&PPrints the page number.
&P+numberPrints the page number plus the specified number.
&P-numberPrints the page number minus the specified number.
&&Prints a single ampersand.
&"font name"Prints the characters that follow in the specified font.
&nnPrints the characters that follow in the specified font size. Use a two digit number to specify a size in points.
&NPrints the total number of pages in the document.

Formatting Headers and Footers in Microsoft Excel

When opening an existing Excel spreadsheet, ExcelWriter will preserve the header and footer formatting created in Excel. However, if you change the header/footer text in your ExcelWriter script and do not include Formatting Codes, the formatting created in Excel will be overwritten, and default formatting applied. To preserve header/footer formatting created in Excel, do not change header/footer text in script.

To format spreadsheet headers and footers in Excel and preserve the formatting in ExcelWriter:

  1. In Microsoft Excel, open the File menu and select Page Setup...


  2. Select the Header/Footer tab.


  3. Select a header and/or footer from the drop-down list.



    Or, create a custom header/footer.



  4. Save the spreadsheet.


  5. In an ExcelWriter script, open the spreadsheet containing headers/footers. Use either ExcelTemplate or ExcelApplication.Open to open the spreadsheet.


  6. Modify the spreadsheet in script. Do not change the text of headers and footers; if you do, the original formatting will be overwritten, and default formatting applied.



Copyright 2007 © SoftArtisans, Inc. All Rights Reserved.