UPDATED:
Starting with version v2015 vol 2 (v15.2), this functionality is available out of the box. Use ASPxGridView.FormatCondition rules to define conditional formatting in Browse Mode and keep the applied appearance in the Exported Document. Please refer to the ASP.NET Grid View - Data Range Filter, Adaptivity and More (Coming soon in v15.2) blog post and the Export with Format Conditions demo for more information.
If you have version v15.2+ available, consider using the built-in functionality instead of the approach detailed below.
If you need to apply custom appearance in the Exported Document only or define fine tuned complex appearance (for instance, based on some runtime calculated values, custom business rules, etc.), use the CsvExportOptionsEx / XlsExportOptionsEx / XlsxExportOptionsEx CustomizeCell event in the Data Aware export mode.
In v2014 vol 2, we introduced the Excel Data Aware Export feature into our grid. While this feature significantly improves the export capabilities (see the New Excel Data Export Engine blog post), it also has some limitations. Most of them are described in the T186064: ASPxGridView / MVC GridView Extension - Excel Data Aware Export FAQ article.
One of them is that the ASPxGridViewExporter.RenderBrick event is not raised when the data-aware export is used. Commonly, this event is used for customizing the cell appearance in resulted documents (a back color, fonts, a format, etc.). While this event is not available, it is still possible to accomplish this task. The XlsxExportOptionsEx object provides the CustomizeCell event that can be used for customizing cells in the exported document:
[C#]varexportOptions=newXlsxExportOptionsEx();exportOptions.CustomizeCell+=exportOptions_CustomizeCell;ASPxGridViewExporter1.WriteXlsxToResponse(exportOptions);...voidexportOptions_CustomizeCell(DevExpress.Export.CustomizeCellEventArgsea){if(ea.ColumnFieldName!="UnitsOnOrder")return;if(Convert.ToInt32(ea.Value)== 0)ea.Formatting.BackColor=Color.Salmon;elseea.Formatting.BackColor=Color.LightGray;ea.Handled=true;}
[VB.NET]Dim exportOptions = New XlsxExportOptionsEx()AddHandler exportOptions.CustomizeCell, AddressOf exportOptions_CustomizeCell ASPxGridViewExporter1.WriteXlsxToResponse(exportOptions) ...PrivateSub exportOptions_CustomizeCell(ByVal ea As DevExpress.Export.CustomizeCellEventArgs)If ea.ColumnFieldName <> "UnitsOnOrder"ThenReturnEndIfIf Convert.ToInt32(ea.Value) = 0 Then ea.Formatting.BackColor = Color.SalmonElse ea.Formatting.BackColor = Color.LightGrayEndIf ea.Handled = TrueEndSub
This example illustrates a sample scenario with exporting a colored grid when the Data Aware export mode is used.
See Also:
How to export the colored ASPxGridView