Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

ASPxGridView - How to export a colored grid when the Data Aware export mode is used

$
0
0

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.


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>