Skip to main content

How to: Print a Workbook

  • 2 minutes to read

The SpreadsheetControl provides the following methods to print a workbook or individual worksheets.

Method Description
SpreadsheetControl.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.
SpreadsheetControl.ShowPrintDialog Invokes the Print dialog that allows you to select a printer and change print settings.
using DevExpress.Spreadsheet;
using System.Drawing.Printing;
// ...

// Load a document into SpreadsheetControl.

// 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 document using the specified printer settings.

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.

Call the SpreadsheetControl.ShowPrintPreview or SpreadsheetControl.ShowRibbonPrintPreview method to invoke the Print Preview window that enables previewing the document before printing. See How to: Show a Print Preview Form for a Document for more details.

See Also