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)