Back to Devexpress

How to: Print a Workbook

wpf-16405-controls-and-libraries-spreadsheet-examples-printing-how-to-print-a-workbook.md

latest3.9 KB
Original Source

How to: Print a Workbook

  • Jun 07, 2019
  • 2 minutes to read

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

MethodDescription
SpreadsheetControl.PrintPrints a document using the default or custom printer settings defined by the PrinterSettings class instance.
Sheet.PrintPrints a particular sheet in the document.
SpreadsheetControl.ShowPrintDialogInvokes the Print dialog that allows you to select a printer and change print settings.
csharp
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);
vb
Imports DevExpress.Spreadsheet
Imports System.Drawing.Printing
' ...

' Load a document into SpreadsheetControl.
spreadsheetControl.Document.LoadDocument("Documents\Document.xlsx")

' Create an object containing printer settings.
Dim printerSettings As 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)

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

Print Spreadsheet Documents

How to: Specify Print Settings

How to: Show a Print Preview Form for a Document