Skip to main content

GridExportCustomizeCellEventArgs.Handled Property

Indicates that the action is handled and your cell customizations should be applied.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public bool Handled { get; set; }

Property Value

Type Description
Boolean

true to apply the cell customizations; false to ignore the cell customizations and export the sell with the default settings.

Remarks

The CustomizeCell action allows you to customize a cell in the exported file. Set the Handled property to true to apply changes made in the action handler. Otherwise, a cell is exported using the default settings.

Run Demo: Grid - Export Data

@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

See Also