Workbook.Print(PrinterSettings) Method
Prints the document using the specified printer settings.
You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this method in production code.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Docs.v24.1.dll
NuGet Package: DevExpress.Document.Processor
Declaration
Parameters
Name | Type | Description |
---|---|---|
printerSettings | PrinterSettings | A PrinterSettings object that contains printer settings. |
Remarks
Use this Print
method overload to print a workbook with the custom printer settings.
The PrinterSettings class allows you to specify printer settings: the printer’s name, the number of copies, a print range, and so on. The Margins or Landscape property (accessible by the PrinterSettings.DefaultPageSettings
property) do not affect the printed workbook’s layout.
using DevExpress.Spreadsheet;
using System.Drawing.Printing;
// ...
// Create a new Workbook object.
Workbook workbook = new Workbook();
// Load a document from a file.
workbook.LoadDocument("Documents\\Document.xlsx");
// Create an object that contains 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 workbook using the specified printer settings.
workbook.Print(printerSettings);
Note
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.
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 by 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 how to specify print settings and print a workbook, refer to this example section: Printing.
Warning
The Print(PrinterSettings)
method overload works only on Windows OS. The PlatformNotSupportedException
is thrown on other operating systems. Use the Print
method overloads with DXPrinterSettings printerSettings
parameter to print on other operating systems.
Calculate Formulas Before Print Operation
The default calculation mode for a Workbook is Manual. This mode implies that the Spreadsheet does not calculate formulas before it prints a document. Call the Workbook.Calculate or Workbook.CalculateFull method to calculate all formulas in the workbook.