blazor-devexpress-dot-blazor-dot-gridexportoptions.md
Allows you to customize a cell in the exported file.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public Action<GridExportCustomizeCellEventArgs> CustomizeCell { get; set; }
| Type | Description |
|---|---|
| Action<GridExportCustomizeCellEventArgs> |
A delegate method that customize the cell.
|
The CustomizeCell action allows you to perform the following actions.
Set the Handled property to true to apply the specified settings. Otherwise, the cell is exported with the default settings.
The table below lists properties that you can use to get additional information about the processed cell depending on the processed area type (AreaType).
| Area Type | Useful property | Property that returns null |
|---|---|---|
Header | ColumnFieldName | DataItem, SummaryItem, GroupFieldName |
GroupHeader | ColumnFieldName, GroupFieldName | DataItem, SummaryItem |
DataArea | ColumnFieldName, DataItem | SummaryItem, GroupFieldName |
GroupFooter | ColumnFieldName, GroupFieldName, SummaryItem | DataItem |
TotalFooter | ColumnFieldName, SummaryItem | DataItem, GroupFieldName |
The GetRowValue(String) method returns the value of the specified data field in the current row.
Run Demo: Grid - Export DataView Example: Customize Export Settings
@using System.Xml;
<DxGrid @ref="Grid" Data="@Data" >
<Columns>
<DxGridDataColumn FieldName="OrderDate" />
<DxGridDataColumn FieldName="CompanyName" />
<DxGridDataColumn FieldName="Country" />
<DxGridDataColumn FieldName="UnitPrice" DisplayFormat="c" />
<DxGridDataColumn FieldName="Quantity" />
<DxGridDataColumn FieldName="Total" UnboundType="GridUnboundColumnType.Decimal"
DisplayFormat="c" UnboundExpression="[UnitPrice]*[Quantity]" />
</Columns>
</DxGrid>
<DxButton Text="Export in Euro" Click="ExportXlsx_Click" />
@code {
object Data { get; set; }
IGrid Grid { get; set; }
protected override async Task OnInitializedAsync() {
var invoices = await NwindDataService.GetInvoicesAsync();
var customers = await NwindDataService.GetCustomersAsync();
Data = invoices.OrderBy(i => i.OrderDate).Join(customers, i => i.CustomerId, c => c.CustomerId, (i, c) => {
return new {
OrderDate = i.OrderDate,
CompanyName = c.CompanyName,
City = i.City,
Region = i.Region,
Country = i.Country,
UnitPrice = i.UnitPrice,
Quantity = i.Quantity
};
});
}
decimal GetRate() {
string daylyRate = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";
decimal rate = 0;
XmlTextReader reader = new XmlTextReader(daylyRate);
while (reader.Read()) {
if (reader.NodeType == XmlNodeType.Element && reader.MoveToAttribute("currency")) {
if (reader.Value == "USD") {
reader.MoveToAttribute("rate");
rate = Convert.ToDecimal(reader.Value);
break;
}
}
}
return rate;
}
async Task ExportXlsx_Click() {
decimal currentRate = GetRate();
var options = new GridXlExportOptions();
options.DocumentCulture = new CultureInfo("fr-FR");
options.SheetName = "(Rate = " + currentRate + ")";
options.CustomizeCell = e => {
if (e.AreaType == DevExpress.Export.SheetAreaType.DataArea && (e.ColumnFieldName == "Total" || e.ColumnFieldName == "UnitPrice")) {
e.Value = (decimal)e.Value / currentRate;
// Highlight data cells where Total > 1000€
if (e.ColumnFieldName == "Total" && (decimal)e.Value > 1000) {
e.Formatting.BackColor = System.Drawing.Color.LightGreen;
}
e.Handled = true;
}
};
await Grid.ExportToXlsxAsync("ExportResult", options);
}
}
For additional information about data export in the Grid component, refer to the following topic: Export Blazor Grid Data to XLS/XLSX.
See Also