blazor-devexpress-dot-blazor-dot-gridxlexportoptions-5ffb8453.md
Allows you to customize sheet settings in the exported document.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public Action<GridExportCustomizeSheetEventArgs> CustomizeSheet { get; set; }
| Type | Description |
|---|---|
| Action<GridExportCustomizeSheetEventArgs> |
A delegate method that customizes sheet settings.
|
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 following code snippet enables the filter in the CustomizeSheet action.
The following code snippet specifies the following sheet settings:
<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 additional information about data export in the Grid component, refer to the following topic: Export Blazor Grid Data to XLS/XLSX.
See Also