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.
spreadsheetControl.Document.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 document using the specified printer settings.
spreadsheetControl.Print(printerSettings); 

The Margins or Landscape property (accessible by the PrinterSettings.DefaultPageSettings property) do not affect the printed workbook’s layout. Use the WorksheetView and WorksheetPrintOptions class properties specify various printout options to control how the document is printed. Refer to the following article for a code sample: How to: Specify Print Settings.

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