GemBox.Spreadsheet is a .NET component that enables you to read, write, edit, convert, and print spreadsheet files from your .NET applications using one simple API.

Print Titles and Area

Following example demonstrates how to set worksheet print titles and print area.

Screenshot
Print Titles and Area Screenshot

See the full code below, use Run Example to execute.

using System;
using System.Collections.Generic;
using System.Text;
using GemBox.Spreadsheet;
using GemBox.Spreadsheet.ConditionalFormatting;
using GemBox.Spreadsheet.PivotTables;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        ExcelFile ef = new ExcelFile();

        // Always print 1st row.
        ExcelWorksheet ws1 = ef.Worksheets.Add("Sheet1");
        ws1.NamedRanges.SetPrintTitles(ws1.Rows[0], 1);

        // Set print area (from A1 to I120):
        ws1.NamedRanges.SetPrintArea(ws1.Cells.GetSubrange("A1", "I120"));

        // Always print columns from A to F.
        ExcelWorksheet ws2 = ef.Worksheets.Add("Sheet2");
        ws2.NamedRanges.SetPrintTitles(ws2.Columns[0], 6);

        // Always print columns from A to F and first row.
        ExcelWorksheet ws3 = ef.Worksheets.Add("Sheet3");
        ws3.NamedRanges.SetPrintTitles(ws3.Rows[0], 1, ws3.Columns[0], 6);

        // Fill Sheet1 with some data
        for (int i = 0; i < 9; i++)
            ws1.Cells[0, i].Value = "Column " + ExcelColumnCollection.ColumnIndexToName(i);

        for (int i = 1; i < 120; i++)
            for (int j = 0; j < 9; j++)
                ws1.Cells[i, j].SetValue(i + j);

        ef.Save("Print Titles and Area.xlsx");
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports GemBox.Spreadsheet
Imports GemBox.Spreadsheet.ConditionalFormatting
Imports GemBox.Spreadsheet.PivotTables

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        Dim ef As ExcelFile = New ExcelFile

        ' Always print 1st row.
        Dim ws1 = ef.Worksheets.Add("Sheet1")
        ws1.NamedRanges.SetPrintTitles(ws1.Rows(0), 1)

        ' Set print area (from A1 to I120):
        ws1.NamedRanges.SetPrintArea(ws1.Cells.GetSubrange("A1", "I120"))

        ' Always print columns from A to F.
        Dim ws2 = ef.Worksheets.Add("Sheet2")
        ws2.NamedRanges.SetPrintTitles(ws2.Columns(0), 6)

        ' Always print columns from A to F and first row.
        Dim ws3 = ef.Worksheets.Add("Sheet3")
        ws3.NamedRanges.SetPrintTitles(ws3.Rows(0), 1, ws3.Columns(0), 6)

        ' Fill Sheet1 with some data
        For i As Integer = 0 To 8
            ws1.Cells(0, i).Value = "Column " + ExcelColumnCollection.ColumnIndexToName(i)
        Next

        For i As Integer = 1 To 119
            For j As Integer = 0 To 8
                ws1.Cells(i, j).SetValue(i + j)
            Next
        Next

        ef.Save("Print Titles and Area.xlsx")

    End Sub

End Module

Check next sample.