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 Excel in C# and VB.NET

The following example demonstrates how to print an entire Excel file in C# and VB.NET using GemBox.Spreadsheet with the default and advanced print options specified via WPF's PrintDialog box.

Note that you can print to the default printer or to any other local or networked printer.

Screenshot
Print Excel Screenshot

See the full code below.

<Window x:Class="PrintCs.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Printing" Height="600" Width="800">
    <DockPanel>
         <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Margin="2">
            <Button x:Name="LoadFileBtn" Content="Load file" Width="100" Margin="2,0" Click="LoadFileBtn_Click"/>
            <Button x:Name="SimplePrintFileBtn" Content="Print" Width="65" Click="SimplePrint_Click" Margin="2,0"/>
            <Button x:Name="AdvancedPrintFileBtn" Content="Print (select options)" Width="130" Click="AdvancedPrint_Click" Margin="2,0"/>
         </StackPanel>
        <DocumentViewer x:Name="DocViewer"/>
    </DockPanel>
</Window>
using System.Windows;
using System.Windows.Controls;
using System.Windows.Xps.Packaging;
using GemBox.Spreadsheet;
using Microsoft.Win32;

namespace PrintCs
{
    public partial class MainWindow : Window
    {
        private ExcelFile ef;

        public MainWindow()
        {
            SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

            InitializeComponent();

            this.EnableControls();
        }

        private void LoadFileBtn_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Filter = "XLSX files (*.xlsx, *.xlsm, *.xltx, *.xltm)|*.xlsx;*.xlsm;*.xltx;*.xltm|XLS files (*.xls, *.xlt)|*.xls;*.xlt|ODS files (*.ods, *.ots)|*.ods;*.ots|CSV files (*.csv, *.tsv)|*.csv;*.tsv|HTML files (*.html, *.htm)|*.html;*.htm";

            if (fileDialog.ShowDialog() == true)
            {
                this.ef = ExcelFile.Load(fileDialog.FileName);

                this.ShowPrintPreview();
                this.EnableControls();
            }
        }

        private void SimplePrint_Click(object sender, RoutedEventArgs e)
        {
            // Print to default printer using default options
            this.ef.Print();
        }

        private void AdvancedPrint_Click(object sender, RoutedEventArgs e)
        {
            // We can use PrintDialog for defining print options
            PrintDialog printDialog = new PrintDialog();
            printDialog.UserPageRangeEnabled = true;

            if (printDialog.ShowDialog() == true)
            {
                PrintOptions printOptions = new PrintOptions(printDialog.PrintTicket.GetXmlStream());

                printOptions.FromPage = printDialog.PageRange.PageFrom - 1;
                printOptions.ToPage = printDialog.PageRange.PageTo == 0 ? int.MaxValue : printDialog.PageRange.PageTo - 1;

                this.ef.Print(printDialog.PrintQueue.FullName, printOptions);
            }
        }

        // We can use DocumentViewer for print preview (but we don't need).
        private void ShowPrintPreview()
        {
            // XpsDocument needs to stay referenced so that DocumentViewer can access additional required resources.
            // Otherwise, GC will collect/dispose XpsDocument and DocumentViewer will not work.
            XpsDocument xpsDocument = ef.ConvertToXpsDocument(SaveOptions.XpsDefault);
            this.DocViewer.Tag = xpsDocument;

            this.DocViewer.Document = xpsDocument.GetFixedDocumentSequence();
        }  

        private void EnableControls()
        {
            bool isEnabled = this.ef != null;

            this.DocViewer.IsEnabled = isEnabled;
            this.SimplePrintFileBtn.IsEnabled = isEnabled;
            this.AdvancedPrintFileBtn.IsEnabled = isEnabled;
        }
    }
}
Imports Microsoft.Win32
Imports GemBox.Spreadsheet

Class MainWindow

    Dim ef As ExcelFile

    Public Sub New()
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        InitializeComponent()

        Me.EnableControls()
    End Sub

    Private Sub LoadFileBtn_Click(sender As Object, e As RoutedEventArgs)

        Dim fileDialog = New OpenFileDialog()
        fileDialog.Filter = "XLSX files (*.xlsx, *.xlsm, *.xltx, *.xltm)|*.xlsx;*.xlsm;*.xltx;*.xltm|XLS files (*.xls, *.xlt)|*.xls;*.xlt|ODS files (*.ods, *.ots)|*.ods;*.ots|CSV files (*.csv, *.tsv)|*.csv;*.tsv|HTML files (*.html, *.htm)|*.html;*.htm"

        If (fileDialog.ShowDialog() = True) Then
            Me.ef = ExcelFile.Load(fileDialog.FileName)

            Me.ShowPrintPreview()
            Me.EnableControls()
        End If

    End Sub

    Private Sub SimplePrint_Click(sender As Object, e As RoutedEventArgs)

        ' Print to default printer using default options
        Me.ef.Print()

    End Sub

    Private Sub AdvancedPrint_Click(sender As Object, e As RoutedEventArgs)

        ' We can use PrintDialog for defining print options
        Dim printDialog = New PrintDialog()
        printDialog.UserPageRangeEnabled = True

        If (printDialog.ShowDialog() = True) Then

            Dim printOptions = New PrintOptions(printDialog.PrintTicket.GetXmlStream())

            printOptions.FromPage = printDialog.PageRange.PageFrom - 1
            If (printDialog.PageRange.PageTo = 0) Then
                printOptions.ToPage = Int32.MaxValue
            Else
                printOptions.ToPage = printDialog.PageRange.PageTo - 1
            End If

            Me.ef.Print(printDialog.PrintQueue.FullName, printOptions)
        End If

    End Sub

    ' We can use DocumentViewer for print preview (but we don't need).
    Private Sub ShowPrintPreview()

        ' XpsDocument needs to stay referenced so that DocumentViewer can access additional required resources.
        ' Otherwise, GC will collect/dispose XpsDocument and DocumentViewer will not work.
        Dim xpsDocument = ef.ConvertToXpsDocument(SaveOptions.XpsDefault)
        Me.DocViewer.Tag = xpsDocument

        Me.DocViewer.Document = xpsDocument.GetFixedDocumentSequence()

    End Sub

    Private Sub EnableControls()

        Dim isEnabled As Boolean = Me.ef IsNot Nothing

        Me.DocViewer.IsEnabled = isEnabled
        Me.SimplePrintFileBtn.IsEnabled = isEnabled
        Me.AdvancedPrintFileBtn.IsEnabled = isEnabled

    End Sub

End Class

Check next sample.