Print Titles and Area

Following sample 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.


1using System;
2using System.Collections.Generic;
3using System.Text;
4using GemBox.Spreadsheet;
5using GemBox.Spreadsheet.ConditionalFormatting;
6using GemBox.Spreadsheet.PivotTables;
7
8class Sample
9{
10    [STAThread]
11    static void Main(string[] args)
12    {
13        // If using Professional version, put your serial key below.
14        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
15
16        ExcelFile ef = new ExcelFile();
17
18        // Always print 1st row.
19        ExcelWorksheet ws1 = ef.Worksheets.Add("Sheet1");
20        ws1.NamedRanges.SetPrintTitles(ws1.Rows[0], 1);
21
22        // Set print area (from A1 to I120):
23        ws1.NamedRanges.SetPrintArea(ws1.Cells.GetSubrange("A1", "I120"));
24
25        // Always print columns from A to F.
26        ExcelWorksheet ws2 = ef.Worksheets.Add("Sheet2");
27        ws2.NamedRanges.SetPrintTitles(ws2.Columns[0], 6);
28
29        // Always print columns from A to F and first row.
30        ExcelWorksheet ws3 = ef.Worksheets.Add("Sheet3");
31        ws3.NamedRanges.SetPrintTitles(ws3.Rows[0], 1, ws3.Columns[0], 6);
32
33        // Fill Sheet1 with some data
34        for (int i = 0; i < 9; i++)
35            ws1.Cells[0, i].Value = "Column " + ExcelColumnCollection.ColumnIndexToName(i);
36
37        for (int i = 1; i < 120; i++)
38            for (int j = 0; j < 9; j++)
39                ws1.Cells[i, j].SetValue(i + j);
40
41        ef.Save("Print Titles and Area.xls");
42    }
43}
1Imports System
2Imports System.Collections.Generic
3Imports System.Text
4Imports GemBox.Spreadsheet
5Imports GemBox.Spreadsheet.ConditionalFormatting
6Imports GemBox.Spreadsheet.PivotTables
7
8Module Samples
9
10    Sub Main()
11
12        ' If using Professional version, put your serial key below.
13        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")
14
15        Dim ef As ExcelFile = New ExcelFile
16
17        ' Always print 1st row.
18        Dim ws1 = ef.Worksheets.Add("Sheet1")
19        ws1.NamedRanges.SetPrintTitles(ws1.Rows(0), 1)
20
21        ' Set print area (from A1 to I120):
22        ws1.NamedRanges.SetPrintArea(ws1.Cells.GetSubrange("A1", "I120"))
23
24        ' Always print columns from A to F.
25        Dim ws2 = ef.Worksheets.Add("Sheet2")
26        ws2.NamedRanges.SetPrintTitles(ws2.Columns(0), 6)
27
28        ' Always print columns from A to F and first row.
29        Dim ws3 = ef.Worksheets.Add("Sheet3")
30        ws3.NamedRanges.SetPrintTitles(ws3.Rows(0), 1, ws3.Columns(0), 6)
31
32        ' Fill Sheet1 with some data
33        For i As Integer = 0 To 8
34            ws1.Cells(0, i).Value = "Column " + ExcelColumnCollection.ColumnIndexToName(i)
35        Next
36
37        For i As Integer = 1 To 119
38            For j As Integer = 0 To 8
39                ws1.Cells(i, j).SetValue(i + j)
40            Next
41        Next
42
43        ef.Save("Print Titles and Area.xls")
44
45    End Sub
46
47End Module

Check next sample or find out more about GemBox.Spreadsheet and GemBox Software.