Print and View Options

Following sample shows how to specify worksheet print and view options.

Screenshot

Print and View Options 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        ExcelWorksheet ws = ef.Worksheets.Add("Print and View Options");
18
19        ws.Cells["M1"].Value = "This worksheet shows how to set various print related and view related options.";
20        ws.Cells["M2"].Value = "To see results of print options, go to Print and Page Setup dialogs in MS Excel.";
21        ws.Cells["M3"].Value = "Notice that print and view options are worksheet based, not workbook based.";
22
23        // Print options:
24        var printOptions = ws.PrintOptions;
25        printOptions.PrintGridlines = true;
26        printOptions.PrintHeadings = true;
27        printOptions.Portrait = false;
28        printOptions.PaperType = PaperType.A3;
29        printOptions.NumberOfCopies = 5;
30
31        // View options:
32        ws.ViewOptions.FirstVisibleColumn = 3;
33        ws.ViewOptions.ShowColumnsFromRightToLeft = true;
34        ws.ViewOptions.Zoom = 123;
35
36        // Set print area
37        ws.NamedRanges.SetPrintArea(ws.Cells.GetSubrange("E1", "U7"));
38
39        ef.Save("Print and View Options.xls");
40    }
41}
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        Dim ws As ExcelWorksheet = ef.Worksheets.Add("Print and View Options")
17
18        ws.Cells("M1").Value = "This worksheet shows how to set various print related and view related options."
19        ws.Cells.GetSubrange("G1", "M1").Merged = True
20        ws.Cells("M2").Value = "To see results of print options, go to Print and Page Setup dialogs in MS Excel."
21        ws.Cells.GetSubrange("G2", "M2").Merged = True
22        ws.Cells("M3").Value = "Notice that print and view options are worksheet based, not workbook based."
23        ws.Cells.GetSubrange("G3", "M3").Merged = True
24
25        ' Print options:
26        Dim printOptions = ws.PrintOptions
27        printOptions.PrintGridlines = True
28        printOptions.PrintHeadings = True
29        printOptions.Portrait = False
30        printOptions.PaperType = PaperType.A3
31        printOptions.NumberOfCopies = 5
32
33        ' View options:
34        ws.ViewOptions.FirstVisibleColumn = 3
35        ws.ViewOptions.ShowColumnsFromRightToLeft = True
36        ws.ViewOptions.Zoom = 123
37
38        ' Set print area
39        ws.NamedRanges.SetPrintArea(ws.Cells.GetSubrange("E1", "U7"))
40
41        ef.Save("Print and View Options.xls")
42
43    End Sub
44
45End Module

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