SpreadsheetControl.Print(PrinterSettings) Method
Prints the document using the specified printer settings.
Namespace: DevExpress.XtraSpreadsheet
Assembly: DevExpress.XtraSpreadsheet.v24.1.dll
NuGet Package: DevExpress.Win.Spreadsheet
Declaration
Parameters
Name | Type | Description |
---|---|---|
printerSettings | PrinterSettings | A PrinterSettings object that contains printer settings. |
Remarks
Use the Print method to print the document using the custom printer settings specified by the PrinterSettings class instance. For example, the PrinterSettings.Copies property allows you to set the number of copies to print, the PrinterSettings.PrinterName property determines the printer to use, and the PrinterSettings.PrintRange property defines a print range. If PrinterSettings.PrintRange is SomePages, use the PrinterSettings.FromPage and PrinterSettings.ToPage properties to specify what pages should be printed.
To print a specific sheet in a workbook, use the Sheet.Print method.
To define general page options, use properties of the WorksheetView object accessible from the Worksheet.ActiveView property. WorksheetView enables you to specify page orientation, margins and paper size settings.
The WorksheetPrintOptions object’s properties allow you to specify more print-specific options, which include scaling, printing gridlines, titles, row and column headings, setting page order and more.
For more information on printing technique in the SpeadsheetControl, refer to the Printing topic.
Example
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);