officefileapi-devexpress-dot-spreadsheet-dot-workbook-dot-print-x28-system-dot-drawing-dot-printing-dot-printersettings-system-dot-collections-dot-generic-dot-ienumerable-system-dot-string-x29.md
Defines printer settings and prints the specified sheets.
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.v25.2.dll
NuGet Package : DevExpress.Document.Processor
public void Print(
PrinterSettings printerSettings,
IEnumerable<string> sheetNames
)
Public Sub Print(
printerSettings As PrinterSettings,
sheetNames As IEnumerable(Of String)
)
| Name | Type | Description |
|---|---|---|
| printerSettings | PrinterSettings |
Specifies printer settings.
| | sheetNames | IEnumerable<String> |
Lists the names of the sheets to be printed.
|
Use this Print method overload to print individual sheets in a workbook. This method prints all the specified sheets despite their Worksheet.VisibilityType property value.
The PrinterSettings class allows you to specify printer settings: the printer’s name, the number of copies, a print range, and so on.
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 = "PrintedDocument.pdf";
// Print specific worksheets in the document.
workbook.Print(printerSettings, new string[] { "Sheet1", "Sheet2" });
Imports DevExpress.Spreadsheet
Imports System.Drawing.Printing
' ...
' Create a new Workbook object.
Dim workbook As New Workbook()
' Load a document from a file.
workbook.LoadDocument("Documents\Document.xlsx")
' Create an object that contains printer settings.
Dim printerSettings As New PrinterSettings()
' Define the printer to use.
printerSettings.PrinterName = "Microsoft Print to PDF"
printerSettings.PrintToFile = True
printerSettings.PrintFileName = "PrintedDocument.pdf"
' Print specific worksheets in the document.
workbook.Print(printerSettings, New String() { "Sheet1", "Sheet2" })
Use the WorksheetView and WorksheetPrintOptions objects’ properties to define page options and specify print settings.
Warning
The Print(PrinterSettings, IEnumerable<String>) 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.
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.
See Also