Back to Devexpress

PivotXlsxExportOptions.CustomizeCell Event

windowsforms-devexpress-dot-xtrapivotgrid-dot-pivotxlsxexportoptions.md

latest5.1 KB
Original Source

PivotXlsxExportOptions.CustomizeCell Event

Allows you to customize a PivotGrid’s cell in the exported XLSX document.

Namespace : DevExpress.XtraPivotGrid

Assembly : DevExpress.XtraPivotGrid.v25.2.dll

NuGet Package : DevExpress.Win.PivotGrid

Declaration

csharp
public event CustomizePivotCellEventHandler CustomizeCell
vb
Public Event CustomizeCell As CustomizePivotCellEventHandler

Remarks

Use the CustomizePivotCellEventArgs.RowType and CustomizePivotCellEventArgs.ColumnType parameters to identify a row and column containing the cell. To specify the cell location in the exported Excel document, use the CustomizePivotCellEventArgs.ExportArea property. To customize the cell format, use the CustomizePivotCellEventArgs.Formatting property.

Note

Set the CustomizePivotCellEventArgs.Handled parameter to true to export cells with custom formatting.

The following example exports data from a PivotGrid Control to Xlsx format. The PivotXlsxExportOptions.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;
    }
}

private void button1_Click(object sender, EventArgs e){
    PivotXlsxExportOptions op = new PivotXlsxExportOptions();
    op.CustomizeCell += op_CustomizeCell;
    pivotGridControl1.ExportToXlsx(fileName, 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 button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim op As New PivotXlsxExportOptions()
    AddHandler op.CustomizeCell, AddressOf op_CustomizeCell
    pivotGridControl1.ExportToXlsx(fileName, op)
End Sub

Note

To customize a PivotGrid’s cell during the export in WYSIWYG mode, use the PivotGridControl.CustomExportFieldValue and PivotGridControl.CustomExportCell events.

More Examples

View Example: Customize Cells in the Exported Excel Document

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomizeCell event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-pivotgrid--customize-cells-in-the-exported-excel-document/CS/WinPivotExportCustomizeCell/Form1.cs#L31

csharp
var exportOptions = new PivotXlsxExportOptions();
exportOptions.CustomizeCell +=
    new CustomizePivotCellEventHandler(exportOptions_CustomizeCell);

winforms-pivotgrid--customize-cells-in-the-exported-excel-document/VB/WinPivotExportCustomizeCell/Form1.vb#L34

vb
Dim exportOptions = New PivotXlsxExportOptions()
AddHandler exportOptions.CustomizeCell, AddressOf exportOptions_CustomizeCell
If filePath <> "" Then

See Also

PivotXlsxExportOptions Class

PivotXlsxExportOptions Members

DevExpress.XtraPivotGrid Namespace