Skip to main content
Row

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.v24.1.dll

NuGet Package: DevExpress.Document.Processor

Declaration

public void Print(
    PrinterSettings printerSettings,
    params string[] sheetNames
)

Parameters

Name Type Description
printerSettings PrinterSettings

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.

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");

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