How to: Print a Workbook

  • 3 min to read
Important

The Print method works only on Windows OS. The PlatformNotSupportedException is thrown on other operating systems.

Use the following methods to print a document:

Method Description
Workbook.Print Prints the entire workbook or individual sheets and allows you to specify printer settings.
Sheet.Print Prints the current sheet.

Use the WorksheetView and WorksheetPrintOptions objects' properties to define page options and specify print settings.

Tip

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

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 that contains 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);
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 that contains printer settings.
PrinterSettings printerSettings = new PrinterSettings();

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

// Print specific worksheets in the document.
workbook.Print(printerSettings, "Sheet1", "Sheet2");
See Also