Skip to main content
Row

Workbook.Print(PrinterSettings, IEnumerable<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.2.dll

NuGet Package: DevExpress.Document.Processor

Declaration

public void Print(
    PrinterSettings printerSettings,
    IEnumerable<string> sheetNames
)

Parameters

Name Type Description
printerSettings PrinterSettings

Specifies printer settings.

sheetNames IEnumerable<String>

Lists the names of the sheets to be printed.

Remarks

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

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.

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