SpreadsheetControl.BeforePrintSheet Event
Provides the capability to prevent printing of the required worksheets in a workbook.
Namespace: DevExpress.XtraSpreadsheet
Assembly: DevExpress.XtraSpreadsheet.v24.1.dll
NuGet Package: DevExpress.Win.Spreadsheet
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 is raised before a workbook is printed or exported to PDF. Use properties of the BeforePrintSheetEventArgs class to get the worksheet being printed or exported by its name or index, and set the Cancel property to true to cancel the print/export operation.
The example below demonstrates how to print the active worksheet only.
using DevExpress.Spreadsheet;
// ...
bool printActiveSheetOnly = true;
//...
private void spreadsheetControl_BeforePrintSheet(object sender, BeforePrintSheetEventArgs e)
{
if (printActiveSheetOnly)
// Cancel printing if the index of the worksheet to be printed is not equal to the active sheet index.
e.Cancel = spreadsheetControl.ActiveWorksheet.Index != e.Index;
}