Back to Devexpress

SpreadsheetControl.BeforePrintSheet Event

windowsforms-devexpress-dot-xtraspreadsheet-dot-spreadsheetcontrol-4dfb8566.md

latest3.2 KB
Original Source

SpreadsheetControl.BeforePrintSheet Event

Provides the capability to prevent printing of the required worksheets in a workbook.

Namespace : DevExpress.XtraSpreadsheet

Assembly : DevExpress.XtraSpreadsheet.v25.2.dll

NuGet Package : DevExpress.Win.Spreadsheet

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 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.

csharp
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;
}
vb
Imports DevExpress.Spreadsheet
' ...

Private printActiveSheetOnly As Boolean = True
'...

Private Sub spreadsheetControl_BeforePrintSheet(ByVal sender As Object, ByVal e As BeforePrintSheetEventArgs)
  If printActiveSheetOnly Then
      ' 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
  End If
End Sub

See Also

SpreadsheetControl Class

SpreadsheetControl Members

DevExpress.XtraSpreadsheet Namespace