Other API Samples

Live SpreadsheetGear API Samples

Page Setup and Printing Samples PrintArea, PrintTitles and Orientation

Demonstrates repeating a Header Row across multiple printed pages and setting the orientation of printed output. On a second worksheet, 2 repeating Header Columns are printed across multiple printed pages.

// Create a new workbook and some local variables.
SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
SpreadsheetGear.IWorksheet worksheet = workbook.ActiveWorksheet;
SpreadsheetGear.IRange cells = worksheet.Cells;
SpreadsheetGear.IPageSetup pageSetup = worksheet.PageSetup;

// Repeating Row Header
{
    // Setup a Title Row (1 row).
    cells["A1:C1"].Value = new object[,] {
        { "Header 1", "Header 2", "Header 3" , "Header 4" }
    };
    cells["A1:C1"].Interior.ThemeColor = SpreadsheetGear.Themes.ColorSchemeIndex.Accent4;

    // Populate a bunch of rows below the Title Row--enough to cause printed output 
    // to wrap multiple pages vertically.
    cells["A2:C100"].Value = "=ROW()+COLUMN()";

    // Set Orientation to Landscape.
    pageSetup.Orientation = SpreadsheetGear.PageOrientation.Landscape;

    // Specify the first row as the Print Title Row, causing it to repeat on the top
    // of each printed page.
    pageSetup.PrintTitleRows = "$1:$1";
}

// Repeating Title Columns (2 columns).
{
    worksheet = workbook.Worksheets.Add();
    cells = worksheet.Cells;
    pageSetup = worksheet.PageSetup;

    // Setup a Header Column consisting of 2 columns.
    cells["A1:B3"].Value = new object[,] {
        { "Header A1" , "Header B1" },
        { "Header A2" , "Header B2" },
        { "Header A3" , "Header B3" }
    };
    cells["A1:B3"].Interior.ThemeColor = SpreadsheetGear.Themes.ColorSchemeIndex.Accent4;

    // Populate a bunch of columns to the right of the title Columns--enough to 
    // cause printed output to wrap multiple pages horizontally.
    cells["C1:Z3"].Value = "=ROW()+COLUMN()";

    // Specify the first row as the Print Title Column, causing it to repeat on 
    // the top of each printed page.
    pageSetup.PrintTitleColumns = "$A:$B";
}
Run This Sample
Download File

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