Skip to content

Update to v25.1 #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CS/GridExportingWithReports/App.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

<Router AppAssembly="@typeof(Program).Assembly">
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
Expand All @@ -8,4 +7,4 @@
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</Router>
6 changes: 3 additions & 3 deletions CS/GridExportingWithReports/GridExportingWithReports.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DevExpress.Blazor" Version="24.2.1-alpha-24207" />
<PackageReference Include="DevExpress.Reporting.Core" Version="24.2.1-alpha-24207" />
<PackageReference Include="DevExpress.Blazor" Version="25.1.3" />
<PackageReference Include="DevExpress.Reporting.Core" Version="25.1.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\images\" />
</ItemGroup>
</Project>
</Project>
20 changes: 10 additions & 10 deletions CS/GridExportingWithReports/Helpers/ExportMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public ExportMiddleware(WeatherForecastService _weatherForecastService) {
weatherForecastService = _weatherForecastService;
}
public Task InvokeAsync(HttpContext context, RequestDelegate next) {
if (context.Request.Path.ToString().StartsWith("/exportPdf")) {
return ExportResult(pdf, GetOptionsFromQuery(context.Request.QueryString.ToString()), context);
if (context.Request.Path.ToString().StartsWith("/exportMht")) {
return ExportResult(mht, GetOptionsFromQuery(context.Request.QueryString.ToString()), context);
}
else if (context.Request.Path.ToString().StartsWith("/exportXlsx")) {
return ExportResult(xlsx, GetOptionsFromQuery(context.Request.QueryString.ToString()), context);
else if (context.Request.Path.ToString().StartsWith("/exportHtml")) {
return ExportResult(html, GetOptionsFromQuery(context.Request.QueryString.ToString()), context);
}
else if (context.Request.Path.ToString().StartsWith("/exportDocx")) {
return ExportResult(docx, GetOptionsFromQuery(context.Request.QueryString.ToString()), context);
Expand All @@ -38,8 +38,8 @@ private DataSourceLoadOptionsBase GetOptionsFromQuery(string query) {
});
return options;
}
private readonly string pdf = "pdf";
private readonly string xlsx = "xlsx";
private readonly string mht = "mht";
private readonly string html = "html";
private readonly string docx = "docx";
private async Task ExportResult(string format, DataSourceLoadOptionsBase dataOptions, HttpContext context) {
XtraReport report = new XtraReport();
Expand All @@ -50,10 +50,10 @@ private async Task ExportResult(string format, DataSourceLoadOptionsBase dataOpt
ReportHelper.CreateReport(report, new string[] { "TemperatureC", "TemperatureF", "Summary", "Date" });
report.CreateDocument();
using (MemoryStream fs = new MemoryStream()) {
if (format == pdf)
report.ExportToPdf(fs);
else if (format == xlsx)
report.ExportToXlsx(fs);
if (format == mht)
report.ExportToMht(fs);
else if (format == html)
report.ExportToHtml(fs);
else if (format == docx)
report.ExportToDocx(fs);
context.Response.Clear();
Expand Down
6 changes: 3 additions & 3 deletions CS/GridExportingWithReports/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ else {
{
string baseUri = NavigationManager.BaseUri.ToString();
exportUrlInfo.Clear();
exportUrlInfo.Add(Tuple.Create(loadOptions.ConvertToGetRequestUri(baseUri + "exportPdf"), "Export PDF"));
exportUrlInfo.Add(Tuple.Create(loadOptions.ConvertToGetRequestUri(baseUri + "exportXlsx"), "Export XLSX"));
exportUrlInfo.Add(Tuple.Create(loadOptions.ConvertToGetRequestUri(baseUri + "exportDocx"), "Export DOCX"));
exportUrlInfo.Add(Tuple.Create(loadOptions.ConvertToGetRequestUri(baseUri + "exportMht"), "Export to MHT"));
exportUrlInfo.Add(Tuple.Create(loadOptions.ConvertToGetRequestUri(baseUri + "exportHtml"), "Export to HTML"));
exportUrlInfo.Add(Tuple.Create(loadOptions.ConvertToGetRequestUri(baseUri + "exportDocx"), "Export to DOCX"));
}
var t = 0;
};
Expand Down
8 changes: 6 additions & 2 deletions CS/GridExportingWithReports/Pages/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using Microsoft.AspNetCore.Components.Web
@using DevExpress.Blazor
@namespace GridExportingWithReports.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

Expand All @@ -8,8 +9,11 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="~/" />
<link href="_content/DevExpress.Blazor.Themes/blazing-berry.bs5.css" rel="stylesheet" />


@foreach(var file in Themes.Fluent.GetFilePaths()) {
<link href="@file" rel="stylesheet" />
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="~/css/site.css" rel="stylesheet" />
<link href="GridExportingWithReports.styles.css" rel="stylesheet" />
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
Expand Down
21 changes: 10 additions & 11 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
<!-- default badges end -->

# Grid for Blazor - How to Export Data to PDF, XLSX, and DOCX formats in a server application
# Blazor Grid - How to Export Data to DOCX, HTML, and MHT formats in a server application

The [Grid](https://docs.devexpress.com/Blazor/403143/grid) component allows you to [export data](https://demos.devexpress.com/blazor/Grid/Export/DataAwareExport) to XLS, XLSX, and CSV file formats. You can also use DevExpress Reporting tools to implement export to different formats (PDF, XLSX, and DOCX). This example illustrates how to do this in a Blazor Server application.
The [Grid](https://docs.devexpress.com/Blazor/403143/grid) component allows you to [export data](https://demos.devexpress.com/blazor/Grid/Export/DataAwareExport) to PDF, XLS, XLSX, and CSV file formats. You can also use DevExpress Reporting tools to implement export to different formats (DOCX, HTML, and MHT). This example illustrates how to do this in a Blazor Server application.

![Exported PDF](images/exported-pdf.png)
![Exported Docx](images/exported-docx.png)

The `DxGrid` component is bound to an [IQueryable<T>](https://docs.microsoft.com/en-us/dotnet/api/system.linq.iqueryable-1) data collection (use the [GridDevExtremeDataSource](https://docs.devexpress.com/Blazor/DevExpress.Blazor.GridDevExtremeDataSource-1)). The [CustomizeLoadOptions](https://docs.devexpress.com/Blazor/DevExpress.Blazor.GridDevExtremeDataSource-1.CustomizeLoadOptions) property is used to obtain information about the grid's state.

To export information, apply the [ExportMiddleware](./CS/GridExportingWithReports/Helpers/ExportMiddleware.cs) type to the application request pipeline. The **ExportMiddleware** handles requests. The response returns the file of the corresponding type.

The [ExportButtons](./CS/GridExportingWithReports/Shared/ExportButtons.razor) component contains export buttons. Each export button contains an [URI to this project](./CS/GridExportingWithReports/Pages/Index.razor#L32), and the URI contains the Grid options. The created report contains only data that is visible in the grid after sort and filter operations. The **ExportMiddleware** processes the request with the URI.

Use the [ReportHelper.CreateReport](./CS/GridExportingWithReports/Helpers/ReportHelper.cs#L9) method with the [ExportToPdf(String)](https://docs.devexpress.com/XtraReports/DevExpress.XtraReports.UI.XtraReport.ExportToPdf(System.String-DevExpress.XtraPrinting.PdfExportOptions))/[ExportToXlsx(Stream)](https://docs.devexpress.com/XtraReports/DevExpress.XtraReports.UI.XtraReport.ExportToXls(System.IO.Stream-DevExpress.XtraPrinting.XlsExportOptions))/[ExportToDocx(Stream)](https://docs.devexpress.com/XtraReports/DevExpress.XtraReports.UI.XtraReport.ExportToDocx(System.IO.Stream-DevExpress.XtraPrinting.DocxExportOptions)) methods to create a report that is exported to the file of the corresponding type.
Use the [ReportHelper.CreateReport](./CS/GridExportingWithReports/Helpers/ReportHelper.cs#L9) method with the [ExportToDocx(Stream)](https://docs.devexpress.com/XtraReports/DevExpress.XtraReports.UI.XtraReport.ExportToDocx(System.IO.Stream-DevExpress.XtraPrinting.DocxExportOptions))/[ExportToHtml(Stream)](https://docs.devexpress.com/XtraReports/DevExpress.XtraReports.UI.XtraReport.ExportToHtml(System.IO.Stream-DevExpress.XtraPrinting.HtmlExportOptions))/[ExportToMht(String)](https://docs.devexpress.com/XtraReports/DevExpress.XtraReports.UI.XtraReport.ExportToMht(System.String-DevExpress.XtraPrinting.MhtExportOptions)) methods to create a report that is exported to the file of the corresponding type.

<!-- default file list -->

Expand All @@ -37,13 +37,12 @@ Use the [ReportHelper.CreateReport](./CS/GridExportingWithReports/Helpers/Report

## More Examples

[Grid for Blazor - How to use DevExpress Reporting tools to implement export in a WASM application](https://github.com/DevExpress-Examples/blazor-webassembly-dxdatagrid-export)

[How to use DevExpress Reporting Components in Blazor applications](https://github.com/DevExpress-Examples/how-to-use-reporting-components-in-blazor-applications)
* [Grid for Blazor - How to use DevExpress Reporting tools to implement export in a WASM application](https://github.com/DevExpress-Examples/blazor-webassembly-dxdatagrid-export)
* [How to use DevExpress Reporting Components in Blazor applications](https://github.com/DevExpress-Examples/how-to-use-reporting-components-in-blazor-applications)
<!-- feedback -->
## Does this example address your development requirements/objectives?

[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=blazor-server-dxgrid-export&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=blazor-server-dxgrid-export&~~~was_helpful=no)

## Does this example address your development requirements/objectives?
[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=blazor-server-dxgrid-export&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=blazor-server-dxgrid-export&~~~was_helpful=no)
(you will be redirected to DevExpress.com to submit your response)
<!-- feedback end -->
Binary file added images/exported-docx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/exported-pdf.png
Binary file not shown.