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 and View Options

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

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();
        ExcelWorksheet ws = ef.Worksheets.Add("Print and View Options");

        ws.Cells["M1"].Value = "This worksheet shows how to set various print related and view related options.";
        ws.Cells["M2"].Value = "To see results of print options, go to Print and Page Setup dialogs in MS Excel.";
        ws.Cells["M3"].Value = "Notice that print and view options are worksheet based, not workbook based.";

        // Print options:
        var printOptions = ws.PrintOptions;
        printOptions.PrintGridlines = true;
        printOptions.PrintHeadings = true;
        printOptions.Portrait = false;
        printOptions.PaperType = PaperType.A3;
        printOptions.NumberOfCopies = 5;

        // View options:
        ws.ViewOptions.FirstVisibleColumn = 3;
        ws.ViewOptions.ShowColumnsFromRightToLeft = true;
        ws.ViewOptions.Zoom = 123;

        // Set print area
        ws.NamedRanges.SetPrintArea(ws.Cells.GetSubrange("E1", "U7"));

        ef.Save("Print and View Options.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
        Dim ws As ExcelWorksheet = ef.Worksheets.Add("Print and View Options")

        ws.Cells("M1").Value = "This worksheet shows how to set various print related and view related options."
        ws.Cells.GetSubrange("G1", "M1").Merged = True
        ws.Cells("M2").Value = "To see results of print options, go to Print and Page Setup dialogs in MS Excel."
        ws.Cells.GetSubrange("G2", "M2").Merged = True
        ws.Cells("M3").Value = "Notice that print and view options are worksheet based, not workbook based."
        ws.Cells.GetSubrange("G3", "M3").Merged = True

        ' Print options:
        Dim printOptions = ws.PrintOptions
        printOptions.PrintGridlines = True
        printOptions.PrintHeadings = True
        printOptions.Portrait = False
        printOptions.PaperType = PaperType.A3
        printOptions.NumberOfCopies = 5

        ' View options:
        ws.ViewOptions.FirstVisibleColumn = 3
        ws.ViewOptions.ShowColumnsFromRightToLeft = True
        ws.ViewOptions.Zoom = 123

        ' Set print area
        ws.NamedRanges.SetPrintArea(ws.Cells.GetSubrange("E1", "U7"))

        ef.Save("Print and View Options.xlsx")

    End Sub

End Module

Check next sample.