diff --git a/CS/GridExportingWithReports/App.razor b/CS/GridExportingWithReports/App.razor index bf6c773..c5ac499 100644 --- a/CS/GridExportingWithReports/App.razor +++ b/CS/GridExportingWithReports/App.razor @@ -1,5 +1,4 @@ - - + @@ -8,4 +7,4 @@

Sorry, there's nothing at this address.

-
+
\ No newline at end of file diff --git a/CS/GridExportingWithReports/GridExportingWithReports.csproj b/CS/GridExportingWithReports/GridExportingWithReports.csproj index 1d5411f..a402ef5 100644 --- a/CS/GridExportingWithReports/GridExportingWithReports.csproj +++ b/CS/GridExportingWithReports/GridExportingWithReports.csproj @@ -6,10 +6,10 @@ enable - - + + - \ No newline at end of file + diff --git a/CS/GridExportingWithReports/Helpers/ExportMiddleware.cs b/CS/GridExportingWithReports/Helpers/ExportMiddleware.cs index 4ab427c..e8c3353 100644 --- a/CS/GridExportingWithReports/Helpers/ExportMiddleware.cs +++ b/CS/GridExportingWithReports/Helpers/ExportMiddleware.cs @@ -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); @@ -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(); @@ -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(); diff --git a/CS/GridExportingWithReports/Pages/Index.razor b/CS/GridExportingWithReports/Pages/Index.razor index 53bf4c2..8b488ee 100644 --- a/CS/GridExportingWithReports/Pages/Index.razor +++ b/CS/GridExportingWithReports/Pages/Index.razor @@ -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; }; diff --git a/CS/GridExportingWithReports/Pages/_Layout.cshtml b/CS/GridExportingWithReports/Pages/_Layout.cshtml index 7a8bef5..b0427e0 100644 --- a/CS/GridExportingWithReports/Pages/_Layout.cshtml +++ b/CS/GridExportingWithReports/Pages/_Layout.cshtml @@ -1,4 +1,5 @@ @using Microsoft.AspNetCore.Components.Web +@using DevExpress.Blazor @namespace GridExportingWithReports.Pages @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @@ -8,8 +9,11 @@ - - + + @foreach(var file in Themes.Fluent.GetFilePaths()) { + + } + diff --git a/Readme.md b/Readme.md index 0638152..df6c24f 100644 --- a/Readme.md +++ b/Readme.md @@ -5,11 +5,11 @@ [![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives) -# 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](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. @@ -17,7 +17,7 @@ To export information, apply the [ExportMiddleware](./CS/GridExportingWithReport 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. @@ -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) -## Does this example address your development requirements/objectives? - -[](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=blazor-server-dxgrid-export&~~~was_helpful=yes) [](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? + +[](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=blazor-server-dxgrid-export&~~~was_helpful=yes) [](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) diff --git a/images/exported-docx.png b/images/exported-docx.png new file mode 100644 index 0000000..73f8355 Binary files /dev/null and b/images/exported-docx.png differ diff --git a/images/exported-pdf.png b/images/exported-pdf.png deleted file mode 100644 index b47a2e3..0000000 Binary files a/images/exported-pdf.png and /dev/null differ