This example shows how to color the exported grid when Data Aware export mode is used.
The grid does not export cell styles applied in the HtmlDataCellPrepared event.
To color the exported grid in Data Aware export mode, handle the XlsxExportOptionsEx.CustomizeCell event.
void ExportOptions_CustomizeCell(DevExpress.Export.CustomizeCellEventArgs ea) {
if (ea.ColumnFieldName != "UnitsOnOrder" || ea.AreaType != DevExpress.Export.SheetAreaType.DataArea) return;
int cellValue = 0;
if (int.TryParse(ea.Value.ToString(), out cellValue) && cellValue == 0) {
ea.Formatting.BackColor = Color.Salmon;
ea.Formatting.Font.Color = Color.Blue;
ea.Formatting.Font.Bold = true;
}
else
ea.Formatting.BackColor = Color.LightBlue;
ea.Handled = true;
}
Note
Starting from v15.2, the grid maintains conditional formatting styles in the exported document. You can use the ASPxGridView.FormatConditions rules to define conditional formatting in browse mode and keep the applied appearance in the exported document.
- Default.aspx.cs (VB: Default.aspx.vb)
- Default.aspx (VB: Default.aspx)
- Grid View for Web Forms - How to export a colored grid in WYSIWYG export mode
- Grid View for MVC - How to export a colored grid in Data Aware export mode
- Grid View for MVC - How to export a colored grid in WYSIWYG export mode
(you will be redirected to DevExpress.com to submit your response)