Skip to main content

GridXlExportOptions.CustomizeSheet Property

Allows you to customize sheet settings in the exported document.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public Action<GridExportCustomizeSheetEventArgs> CustomizeSheet { get; set; }

Property Value

Type Description
Action<GridExportCustomizeSheetEventArgs>

A delegate method that customizes sheet settings.

Remarks

Implement a delegate for the CustomizeSheet action to customize settings of the sheet in the output document. Use the argument’s Sheet property to access sheet settings.

View Example: Customize Export Settings

When you create a delegate for the CustomizeSheet action, the grid disables some predefined sheet settings that can be set in this handler. For instance, the auto filter is initially enabled for a grid header (the default setting). If you implement the delegate, the auto filter is disabled. The example below demonstrates how to enable the filter in the CustomizeSheet action.

Example

The code sample below specifies the following sheet settings:

  • The AutoFilterRange property applies the auto filter to the specified cell range.
  • The SplitPosition property freezes a specific number of rows and columns.
  • The ShowGridLines option hides the grid lines.
  • The RightToLeft option enables the right-to-left display.
<DxGrid @ref="Grid" Data="@Data" >
    <Columns>
        <DxGridSelectionColumn AllowSelectAll="true" />
        <DxGridDataColumn FieldName="ContactName" />
        <DxGridDataColumn FieldName="ContactTitle" />
        <DxGridDataColumn FieldName="CompanyName" />
        <DxGridDataColumn FieldName="Country" />
    </Columns>
</DxGrid>
<DxButton Text="Export to XLSX" Click="ExportXlsx_Click" />
@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() {
        var options = new GridXlExportOptions();
        options.CustomizeSheet = CustomizeSheet;
        await Grid.ExportToXlsxAsync("ExportResult", options);
    }
    void CustomizeSheet(GridExportCustomizeSheetEventArgs e) {
        // Enable auto filter for columns with data
        var positionStart = new DevExpress.Export.Xl.XlCellPosition(0, 0);
        var positionEnd = new DevExpress.Export.Xl.XlCellPosition(Grid.GetDataColumns().Count-1, 0);
        e.Sheet.AutoFilterRange = new DevExpress.Export.Xl.XlCellRange(positionStart, positionEnd);

        // Freeze the left column and top two rows
        e.Sheet.SplitPosition = new DevExpress.Export.Xl.XlCellPosition(1, 2);

        // Hide the grid lines
        e.Sheet.ViewOptions.ShowGridLines = false;

        // Export data in right-to-left representation
        e.Sheet.ViewOptions.RightToLeft = true;
    }
}

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

See Also