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.v23.2.dll
NuGet Package: DevExpress.Document.Processor
Declaration
Parameters
Name | Type | Description |
---|---|---|
printerSettings | PrinterSettings | A PrinterSettings object that contains printer settings. |
Remarks
Use the current Print method overload to print a workbook 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.
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 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 how to specify print settings and print a workbook, refer to this example section: Printing.
Warning
The Print
method works only on Windows OS. The PlatformNotSupportedException
is thrown 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.