Back to Devexpress

PivotGridXlsExportOptions.CustomizeCell Event

wpf-devexpress-dot-xpf-dot-pivotgrid-dot-pivotgridxlsexportoptions.md

latest3.2 KB
Original Source

PivotGridXlsExportOptions.CustomizeCell Event

Allows you to customize a PivotGrid cell in the exported XLS document. Only available in data-aware export mode.

Namespace : DevExpress.Xpf.PivotGrid

Assembly : DevExpress.Xpf.PivotGrid.v25.2.dll

NuGet Package : DevExpress.Wpf.PivotGrid

Declaration

csharp
public event CustomizePivotCellEventHandler CustomizeCell
vb
Public Event CustomizeCell As CustomizePivotCellEventHandler

Remarks

Follow the steps below to customize data in the output document.

  1. Create the PivotGridXlsExportOptions instance.
  2. Handle the PivotGridXlsExportOptions.CustomizeCell event.
  3. Use the CustomizePivotCellEventArgs.Formatting property to specify the cell’s appearance settings.
  4. Use the CustomizePivotCellEventArgs.ValueItemInfo property to specify the field to which the customized cell belongs.
  5. To export cells with custom formatting, set the Handled parameter to true.
  6. To export customized data from a PivotGrid Control, pass the PivotGridXlsExportOptions instance to the ExportToXls method.

The following example exports data from a PivotGrid Control to Xls format. The PivotGridXlsExportOptions.CustomizeCell event is used to change the background color of the “Category Name” column in the output document.

csharp
//...
void op_CustomizeCell(CustomizePivotCellEventArgs e){
       if (e.ValueItemInfo != null && e.ValueItemInfo.Field == fieldCategoryName) 
      {
          e.Formatting.BackColor = Color.AliceBlue;
          e.Handled = true;
      }

  }
void Button_Click(object sender, RoutedEventArgs e) {
    PivotGridXlsExportOptions op = new PivotGridXlsExportOptions();
    op.CustomizeCell += op_CustomizeCell;
    pivorGrid1.ExportToXls(file, op);
}
vb
'...
Private Sub op_CustomizeCell(ByVal e As CustomizePivotCellEventArgs)
      If e.ValueItemInfo IsNot Nothing AndAlso e.ValueItemInfo.Field = fieldCategoryName Then
          e.Formatting.BackColor = Color.AliceBlue
          e.Handled = True
      End If

End Sub
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim op As New PivotGridXlsExportOptions()
    AddHandler op.CustomizeCell, AddressOf op_CustomizeCell
    pivorGrid1.ExportToXls(file, op)
End Sub

See Also

CustomizePivotCellEventArgs

PivotGridXlsExportOptions Class

PivotGridXlsExportOptions Members

DevExpress.Xpf.PivotGrid Namespace