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.Formatting Property

Returns an object that defines the cell formatting settings (font, alignment, background color, format string, etc.).

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public XlFormattingObject Formatting { get; set; }

#Property Value

Type Description
XlFormattingObject

The object that contains cell formatting settings.

#Remarks

The CustomizeCell action allows you to customize a cell in the exported file. Use the Formatting property to format the cell’s value and appearance.

Set the Handled property to true to apply the changes made in the action handler to the cell.

razor
<DxGrid @ref="Grid"
        Data="@Data"
        SelectionMode="GridSelectionMode.Multiple">
    <Columns>
        <DxGridSelectionColumn Width="60px" AllowSelectAll="true" />
        <DxGridDataColumn FieldName="ContactName" Width="15%" />
        <DxGridDataColumn FieldName="ContactTitle" Width="15%" />
        <DxGridDataColumn FieldName="CompanyName" Width="20%" />
        <DxGridDataColumn FieldName="Country" Width="15%" />
        <DxGridDataColumn FieldName="FullAddress" UnboundType="GridUnboundColumnType.String" 
                          UnboundExpression="[City] + ' - ' + [PostalCode] + ' - ' + [Address]" />
    </Columns>
</DxGrid>
@* ... *@
<OptionButton Text="Export to XLS" OnClick="ExportXls_Click" />
@* ... *@
@code {
    IEnumerable<object> Data { get; set; }
    IGrid Grid { get; set; }
    protected override async Task OnInitializedAsync() {
        Data = await NwindDataService.GetCustomersAsync();
    }
    async Task ExportXls_Click() {
       await Grid.ExportToXlsAsync("ExportResult", new GridXlExportOptions() {
            ExportSelectedRowsOnly = true,
            CustomizeCell = OnCustomizeCell
        });
    }
    void OnCustomizeCell (GridExportCustomizeCellEventArgs args) {
        if(args.ColumnFieldName == "ContactName" && args.AreaType == SheetAreaType.DataArea)
            args.Formatting.Font = new XlCellFont() { Italic = true };
        args.Handled = true;
    }
}

Run Demo: Grid - Export Data

See Also