Other API Samples

Live SpreadsheetGear API Samples

Page Setup and Printing Samples Print Headers and Footers

Demonstrates using various codes to add content and formatting to the Print Headers and Footers, including adding an embedded picture.

// Open workbook with some sample data.
SpreadsheetGear.IWorkbook workbook = 
SpreadsheetGear.IWorksheet worksheet = workbook.ActiveWorksheet;

// Get page setup object for the worksheet.
SpreadsheetGear.IPageSetup pageSetup = worksheet.PageSetup;

// Load picture into byte array (would also accept a path to a file).
byte[] pictureBytes = System.IO.File.ReadAllBytes(@"Files\SpreadsheetGearLogo.png");

// Add picture into Left Header and specify picture code (&G) to render it. 
pageSetup.LeftHeaderPicture.Add(pictureBytes, 32, 32);
pageSetup.LeftHeader = "&G";

// Specify Center Header text, also applying to it Bold (&B), Underline (&U) and 
// Arial 16pt (&16&"Arial").
pageSetup.CenterHeader = @"&B&U&16&""Arial""SpreadsheetGear Report";

// Setup Right Header with Current Page Number (&P) and Total Page Count (&N).
pageSetup.RightHeader = "Page &P of &N";

// Setup Left Footer with current Date (&D) and Time (&T).
pageSetup.LeftFooter = "&D &T";

// Setup Right Footer, in Italics (&I), with Workbook Name (&F) and Worksheet 
// Name (&A).
pageSetup.RightFooter = "&I'&F'!&A";
Run This Sample
Download File

Download an Excel Open XML Workbook (*.xlsx) file with the results of this sample.

Supporting Files

The following files are utilized by this sample: