officefileapi-devexpress-dot-spreadsheet-dot-workbook-eb8bc9a1.md
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.v25.2.dll
NuGet Package : DevExpress.Document.Processor
public event BeforePrintSheetEventHandler BeforePrintSheet
Public Event BeforePrintSheet As BeforePrintSheetEventHandler
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. |
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;
}
Shared workbook As Workbook
Private Shared Sub Main(ByVal args As String())
workbook = New Workbook()
workbook.LoadDocument("Documents\Spreadsheet Book.xls")
workbook.BeforePrintSheet += AddressOf Workbook_BeforePrintSheet
End Sub
Private Shared Sub Workbook_BeforePrintSheet(ByVal sender As Object, ByVal e As BeforePrintSheetEventArgs)
If workbook.Worksheets(e.Name).Shapes.Count <> 0 Then e.Cancel = True
End Sub
See Also