Back to Devexpress

Workbook.BeforePrintSheet Event

officefileapi-devexpress-dot-spreadsheet-dot-workbook-eb8bc9a1.md

latest3.3 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public event BeforePrintSheetEventHandler BeforePrintSheet
vb
Public Event BeforePrintSheet As BeforePrintSheetEventHandler

Event Data

The BeforePrintSheet event's data class is BeforePrintSheetEventArgs. The following properties provide information specific to this event:

PropertyDescription
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
IndexReturns the index of the worksheet to be printed.
NameReturns 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).

csharp
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;
}
vb
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

Implements

BeforePrintSheet

See Also

Workbook Class

Workbook Members

DevExpress.Spreadsheet Namespace