Workbook.BeforePrintSheet Event
Occurs before printing a workbook.
You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this event in production code.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Docs.v24.2.dll
NuGet Package: DevExpress.Document.Processor
Declaration
Event Data
The BeforePrintSheet event's data class is BeforePrintSheetEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Cancel | Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs. |
Index | Returns the index of the worksheet to be printed. |
Name | Returns the name of the worksheet to be printed. |
Remarks
The BeforePrintSheet event fires for each worksheet being printed or exported to PDF. To cancel the print/export operation, set e.Cancel to true.
The code sample below shows how to cancel printing or exporting to PDF worksheets with drawing objects (shapes, pictures and charts).
static Workbook workbook;
static void Main(string[] args)
{
workbook = new Workbook();
workbook.LoadDocument("Documents\\Spreadsheet Book.xls");
workbook.BeforePrintSheet += Workbook_BeforePrintSheet;
}
private static void Workbook_BeforePrintSheet(object sender, BeforePrintSheetEventArgs e)
{
if (workbook.Worksheets[e.Name].Shapes.Count != 0) e.Cancel = true;
}