Back to Devexpress

How to: Show a Print Preview Form for a Workbook

officefileapi-16631-spreadsheet-document-api-examples-printing-how-to-show-a-print-preview-form-for-a-workbook.md

latest3.3 KB
Original Source

How to: Show a Print Preview Form for a Workbook

  • Sep 19, 2023
  • 2 minutes to read

This example demonstrates how to use the DevExpress Printing Library to show a Print Preview for a document loaded into a Workbook instance (workbook, in this example). To do this, follow the steps below:

View Example

csharp
using DevExpress.Spreadsheet;
using DevExpress.XtraPrinting;

// Invoke the Print Preview dialog for the workbook.
using (PrintingSystem printingSystem = new PrintingSystem()) {
    using (PrintableComponentLink link = new PrintableComponentLink(printingSystem)) {
        link.Component = workbook;
        link.CreateDocument();
        link.ShowPreviewDialog();
    }
}
vb
Imports DevExpress.Spreadsheet
Imports DevExpress.XtraPrinting

' Invoke the Print Preview dialog for the workbook.
Using printingSystem As New PrintingSystem()
    Using link As New PrintableComponentLink(printingSystem)
        link.Component = workbook
        link.CreateDocument()
        link.ShowPreviewDialog()
    End Using
End Using

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 generates a printout. Call the Workbook.Calculate or Workbook.CalculateFull method to calculate all formulas in the workbook.

See Also

How to: Print a Workbook