Back to Devexpress

Workbook.Print(PrinterSettings, String[]) Method

officefileapi-devexpress-dot-spreadsheet-dot-workbook-dot-print-x28-system-dot-drawing-dot-printing-dot-printersettings-system-dot-string-x29.md

latest5.0 KB
Original Source

Workbook.Print(PrinterSettings, String[]) Method

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

Declaration

csharp
public void Print(
    PrinterSettings printerSettings,
    params string[] sheetNames
)
vb
Public Sub Print(
    printerSettings As PrinterSettings,
    ParamArray sheetNames As String()
)

Parameters

NameTypeDescription
printerSettingsPrinterSettings

Specifies printer settings.

| | sheetNames | String[] |

The names of the sheets to be printed.

|

Remarks

Use this Print method to print individual sheets in a workbook. It prints all the specified sheets despite their visibility type (WorksheetVisibilityType).

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.

csharp
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, "Sheet1", "Sheet2");
vb
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, "Sheet1", "Sheet2")

Use the WorksheetView and WorksheetPrintOptions objects’ properties to define page options and specify print settings.

>[!warning] >The Print(PrinterSettings, 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.

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.

See Also

Workbook Class

Workbook Members

DevExpress.Spreadsheet Namespace