Skip to main content

GridExportOptions.CustomizeCell Property

Allows you to customize a cell in the exported file.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

public Action<GridExportCustomizeCellEventArgs> CustomizeCell { get; set; }

Property Value

Type Description
Action<GridExportCustomizeCellEventArgs>

A delegate method that customize the cell.

Property Paths

You can access this nested property as listed below:

Object Type Path to CustomizeCell
GridExportEventArgs
.Options .CustomizeCell

Remarks

The CustomizeCell action allows you to perform the following actions.

  • Substitute the cell value (Value).
  • Insert a hyperlink in the cell (Hyperlink).
  • Customize the cell’s format (Formatting).

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 Data View 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);
    }
}

Grid - French Culture

For more information about data export in the Grid component, refer to the following topic: Export Data in Blazor Grid.

See Also