Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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