Skip to main content
All docs
V25.1
  • DevExpress v25.1 Update — Your Feedback Matters

    Our What's New in v25.1 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

    GridXlExportOptions Class

    Contains options that define how a document is exported to XLS and XLSX.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v25.1.dll

    NuGet Package: DevExpress.Blazor

    #Declaration

    C#
    public class GridXlExportOptions :
        GridExportOptions,
        IGridXlExportOptions

    #Remarks

    When you export a grid in Microsoft Excel formats (the ExportToXlsAsync or ExportToXlsxAsync method), the GridXlExportOptions object allows you to customize the settings of the exported grid and the output file.

    Razor
    <div class="grid-container">
        <DxGrid @ref="Grid"
                Data="@Data"
                ShowSearchBox="true"
                SearchText="Manager"
                ShowGroupPanel="true"
                AutoExpandAllGroupRows="true"
                GroupFooterDisplayMode="GridGroupFooterDisplayMode.IfExpanded"
                SelectionMode="GridSelectionMode.Multiple"
                SelectAllCheckboxMode="GridSelectAllCheckboxMode.AllPages"
                ColumnResizeMode="GridColumnResizeMode.NextColumn"
                TextWrapEnabled="false"
                SizeMode="Params.SizeMode"
                HighlightRowOnHover="true">
            <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%" GroupIndex="0" />
                <DxGridDataColumn FieldName="FullAddress" UnboundType="GridUnboundColumnType.String" UnboundExpression="[City] + ' - ' + [PostalCode] + ' - ' + [Address]" />
            </Columns>
            <TotalSummary>
                <DxGridSummaryItem FieldName="ContactName" SummaryType="GridSummaryItemType.Count" />
            </TotalSummary>
            <GroupSummary>
                <DxGridSummaryItem FieldName="ContactName" SummaryType="GridSummaryItemType.Count" FooterColumnName="ContactName" />
            </GroupSummary>
            <ToolbarTemplate>
                <DxToolbar>
                    <DxToolbarItem Text="Export to XLSX" Click="ExportXlsx_Click" BeginGroup="true" />
                    <DxToolbarItem Text="Export to XLS" Click="ExportXls_Click" BeginGroup="true" />
                    <DxToolbarItem Text="Export to CSV" Click="ExportCsv_Click" BeginGroup="true" />
                    <DxToolbarItem Context="itemCtx" Alignment="ToolbarItemAlignment.Right" BeginGroup="true">
                        <Template>
                            <DxCheckBox @bind-Checked="@ExportSelectedRowsOnly">Export Selected Rows Only</DxCheckBox>
                        </Template>
                    </DxToolbarItem>
                </DxToolbar>
            </ToolbarTemplate>
        </DxGrid>
    </div>
    
    @code {
        IEnumerable<object> Data { get; set; }
        IGrid Grid { get; set; }
        bool ExportSelectedRowsOnly { get; set; }
    
        protected override async Task OnInitializedAsync() {
            Data = await NwindDataService.GetCustomersAsync();
        }
        async Task ExportXlsx_Click() {
            await Grid.ExportToXlsxAsync("ExportResult", new GridXlExportOptions() {
                ExportSelectedRowsOnly = ExportSelectedRowsOnly,
                CustomizeCell = OnCustomizeXlCell
            });
        }
        async Task ExportXls_Click() {
            await Grid.ExportToXlsAsync("ExportResult", new GridXlExportOptions() {
                ExportSelectedRowsOnly = ExportSelectedRowsOnly,
                CustomizeCell = OnCustomizeXlCell
            });
        }
        async Task ExportCsv_Click() {
            await Grid.ExportToCsvAsync("ExportResult", new GridCsvExportOptions() {
                ExportSelectedRowsOnly = ExportSelectedRowsOnly
            });
        }
        void OnCustomizeXlCell (GridExportCustomizeCellEventArgs args) {
            if(args.ColumnFieldName == "ContactName" && args.AreaType == SheetAreaType.DataArea)
                args.Formatting.Font = new XlCellFont() { Italic = true };
            args.Handled = true;
        }
    }
    

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

    #Inheritance

    Object
    DevExpress.Blazor.Internal.GridExportOptionsBase
    GridExportOptions
    GridXlExportOptions
    See Also