aspnet-devexpress-dot-web-dot-aspxpivotgrid-dot-pivotxlsxexportoptions.md
Allows you to specify cell formatting when exporting a Pivot Grid control to XLSX format in data-aware mode.
Namespace : DevExpress.Web.ASPxPivotGrid
Assembly : DevExpress.Web.ASPxPivotGrid.v25.2.dll
NuGet Package : DevExpress.Web
public event CustomizePivotCellEventHandler CustomizeCell
Public Event CustomizeCell As CustomizePivotCellEventHandler
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 that you should set the CustomizePivotCellEventArgs.Handled parameter to true to apply changes.
View Example: How to Export ASP.NET MVC Pivot Grid to PDF and XLSX Formats with Custom Settings
PivotXlsxExportOptions GetXlsxOptions()
{
PivotXlsxExportOptions options = new PivotXlsxExportOptions();
options.CustomizeCell += Options_CustomizeCell;
return options;
}
void Options_CustomizeCell(CustomizePivotCellEventArgs e)
{
if (e.CellItemInfo != null)
{
switch (e.CellItemInfo.ColumnValueType)
{
case PivotGridValueType.GrandTotal:
// Specify the text to display in a cell.
e.Value = string.Format("=> {0}", e.Value.ToString());
// Specify the colors used to paint the cell.
e.Formatting.BackColor = Color.Gray;
e.Formatting.Font.Color = Color.Orange;
break;
case PivotGridValueType.Total:
e.Formatting.BackColor = Color.DarkOliveGreen;
e.Formatting.Font.Color = Color.White;
break;
case PivotGridValueType.Value:
e.Formatting.Font.Color = Color.Gray;
break;
}
e.Handled = true;
}
}
Private Function GetXlsxOptions() As PivotXlsxExportOptions
Dim options As New PivotXlsxExportOptions()
AddHandler options.CustomizeCell, AddressOf Options_CustomizeCell
Return options
End Function
Private Sub Options_CustomizeCell(ByVal e As CustomizePivotCellEventArgs)
If e.CellItemInfo IsNot Nothing Then
Select Case e.CellItemInfo.ColumnValueType
Case PivotGridValueType.GrandTotal
' Specify the text to display in a cell.
e.Value = String.Format("=> {0}", e.Value.ToString())
' Specify the colors used to paint the cell.
e.Formatting.BackColor = Color.Gray
e.Formatting.Font.Color = Color.Orange
Case PivotGridValueType.Total
e.Formatting.BackColor = Color.DarkOliveGreen
e.Formatting.Font.Color = Color.White
Case PivotGridValueType.Value
e.Formatting.Font.Color = Color.Gray
End Select
e.Handled = True
End If
End Sub
Tip
To customize an exported cell in WYSIWYG export mode, handle the following events:
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.
mvc-pivot-grid-custom-export/CS/MVCxPivotGrid_CustomExport/PivotGridHelper/PivotGridHelper.cs#L140
PivotXlsxExportOptions options = new PivotXlsxExportOptions();
options.CustomizeCell += Options_CustomizeCell;
return options;
See Also
Export to Tabular Formats (CSV, XLS, XLSX)