Skip to main content

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.v23.2.dll

NuGet Package: DevExpress.Blazor

Declaration

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.

<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