Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

GridExportCustomizeCellEventArgs.ColumnFieldName Property

Returns the name of the data source field bound to the column that contains the processed cell.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public string ColumnFieldName { get; set; }

#Property Value

Type Description
String

The field name.

#Remarks

The CustomizeCell action allows you to customize a cell in the exported file. Use the ColumnFieldName property to determine the column that contains the processed cell.

razor
<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 to XLSX" Click="ExportXlsx_Click" />
@code {
    object Data { get; set; }
    IGrid Grid { get; set; }
    IEnumerable<GridGroupFooterDisplayMode> DisplayModes { get; } = Enum.GetValues(typeof(GridGroupFooterDisplayMode)).Cast<GridGroupFooterDisplayMode>();
    GridGroupFooterDisplayMode CurrentDisplayMode { get; set; } = GridGroupFooterDisplayMode.Auto;
    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
            };
        });
    }
    async Task ExportXlsx_Click() {
        var options = new GridXlExportOptions();
        options.CustomizeCell = e => {
            // Highlight data cells where Total > 1000 
            if (e.AreaType == DevExpress.Export.SheetAreaType.DataArea && e.ColumnFieldName == "Total" && (decimal)e.Value > 1000) {
                e.Formatting.BackColor = System.Drawing.Color.LightGreen;
                e.Handled = true;
            }
        };
       await Grid.ExportToXlsxAsync("ExportResult", options);
    }
}

Grid - Formatted Cells

Run Demo: Grid - Export Data

See Also