Skip to main content
A newer version of this page is available. .

How to: Print a Workbook

  • 2 minutes to read

The table below lists methods that allow you to print a Workbook or individual worksheets.

Method Description
Workbook.Print Prints a document using the default or custom printer settings defined by the PrinterSettings class instance.
Sheet.Print Prints a particular sheet in the document.
using DevExpress.Spreadsheet;
using System.Drawing.Printing;
// ...

// Create a new Workbook object.
Workbook workbook = new Workbook();

// Load a document from a file.
workbook.LoadDocument("Documents\\Document.xlsx");

// Create an object containing printer settings.
PrinterSettings printerSettings = new PrinterSettings();

// Define the printer to use.
printerSettings.PrinterName = "Microsoft Print to PDF";
printerSettings.PrintToFile = true;
printerSettings.PrintFileName = "Documents\\PrintedDocument.pdf";

// Specify that the first three pages should be printed.
printerSettings.PrintRange = PrintRange.SomePages;
printerSettings.FromPage = 1;
printerSettings.ToPage = 3;

// Set the number of copies to print.
printerSettings.Copies = 1;

// Print the workbook using the specified printer settings.
workbook.Print(printerSettings);

Tip

Handle the Workbook.BeforePrintSheet event to cancel printing the specific worksheet(s).

You can also specify various printout options to control how the document is printed. To do this, use properties of the WorksheetView and WorksheetPrintOptions objects as described in the How to: Specify Print Settings example.

See Also