How to: Show a Print Preview Form for a Workbook
- 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:
- Add a reference to the DevExpress.XtraPrinting.v24.2.dll assembly and explicitly import the DevExpress.XtraPrinting namespace into the code with a using directive (Imports in Visual Basic).
- Create a new PrintingSystem instance for creating and printing a document.
- Create a PrintableComponentLink printing link with the specified printing system and assign the workbook to the PrintableComponentLinkBase.Component property.
- Generate a document to print by calling the LinkBase.CreateDocument method.
- Call the PrintableComponentLink.ShowPreviewDialog method to invoke the print preview form that enables a user to print the document or save it as a PDF or graphic file.
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();
}
}
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