blazor-devexpress-dot-blazor-dot-dxgrid-dot-exporttoxlsxasync-x28-system-dot-string-devexpress-dot-blazor-dot-gridxlexportoptions-x29.md
Exports grid data in XLSX format and downloads the resulting file to the client machine.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public Task ExportToXlsxAsync(
string fileName,
GridXlExportOptions options = null
)
| Name | Type | Description |
|---|---|---|
| fileName | String |
The name of the downloaded file.
|
| Name | Type | Default | Description |
|---|---|---|---|
| options | GridXlExportOptions | null |
An object that contains export options.
|
| Type | Description |
|---|---|
| Task |
The task that is completed when the file is downloaded.
|
Call the ExportToXlsAsync method to export grid data in XLSX format. The method overloads allow you to write the result to a stream (ExportToXlsxAsync(Stream, GridXlExportOptions)) or to a file downloaded to a client machine (the current overload).
The method accepts a GridXlExportOptions object as a parameter. You can use this parameter to set up export settings.
<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 XLSX" OnClick="ExportXlsx_Click" />
@* ... *@
@code {
IEnumerable<object> Data { get; set; }
IGrid Grid { get; set; }
protected override async Task OnInitializedAsync() {
Data = await NwindDataService.GetCustomersAsync();
}
async Task ExportXlsx_Click() {
await Grid.ExportToXlsxAsync("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;
}
}
For additional information about data export in the Grid component, refer to the following topic: Export Blazor Grid Data to XLS/XLSX.
If the grid is bound to a GridDevExtremeDataSource object, the following limitations apply:
See the following article for additional information about Microsoft Excel limitations (for example, row count and column count): Excel specifications and limits.
View Example: Export Images/Rich Text Using Spreadsheet Document APIs
ExportToXlsxAsync(String, GridXlExportOptions)
See Also