|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.Diagnostics; |
4 | | -using System.IO; |
5 | | -using System.Linq; |
6 | | -using System.Threading.Tasks; |
7 | | -using DevExpress.XtraPrinting; |
8 | | -using DevExpress.XtraReports.UI; |
9 | | -using dxSampleReactReportingPrintWithoutPreview.Model; |
10 | | -using dxSampleReactReportingPrintWithoutPreview.PredefinedReports; |
11 | | -using Microsoft.AspNetCore.Mvc; |
12 | | - |
13 | | -namespace dxSampleReactReportingPrintWithoutPreview.Controllers |
14 | | -{ |
15 | | - [Route("api/[controller]")] |
16 | | - public class HomeController : Controller |
17 | | - { |
18 | | - public IActionResult Index() |
19 | | - { |
20 | | - return View(); |
21 | | - } |
22 | | - |
23 | | - public IActionResult Error() |
24 | | - { |
25 | | - ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier; |
26 | | - return View(); |
27 | | - } |
28 | | - [HttpGet("[action]")] |
29 | | - public async Task<object> Print() |
30 | | - { |
31 | | - var report = new TestReport(); |
32 | | - using (var ms = new MemoryStream()) |
33 | | - { |
34 | | - await report.ExportToPdfAsync(ms, new DevExpress.XtraPrinting.PdfExportOptions { ShowPrintDialogOnOpen = true }); |
35 | | - return File(ms.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf); |
36 | | - } |
37 | | - } |
38 | | - [HttpGet("[action]")] |
39 | | - public ActionResult Export(string format = "pdf") |
40 | | - { |
41 | | - format = format.ToLower(); |
42 | | - XtraReport report = new TestReport(); |
43 | | - string contentType = string.Format("application/{0}", format); |
44 | | - using (MemoryStream ms = new MemoryStream()) |
45 | | - { |
46 | | - switch (format) |
47 | | - { |
48 | | - case "pdf": |
49 | | - contentType = "application/pdf"; |
50 | | - report.ExportToPdf(ms); |
51 | | - break; |
52 | | - case "docx": |
53 | | - contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; |
54 | | - report.ExportToDocx(ms); |
55 | | - break; |
56 | | - case "xls": |
57 | | - contentType = "application/vnd.ms-excel"; |
58 | | - report.ExportToXls(ms); |
59 | | - break; |
60 | | - case "xlsx": |
61 | | - contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; |
62 | | - report.ExportToXlsx(ms); |
63 | | - break; |
64 | | - case "rtf": |
65 | | - report.ExportToRtf(ms); |
66 | | - break; |
67 | | - case "mht": |
68 | | - contentType = "message/rfc822"; |
69 | | - report.ExportToMht(ms); |
70 | | - break; |
71 | | - case "html": |
72 | | - contentType = "text/html"; |
73 | | - report.ExportToHtml(ms); |
74 | | - break; |
75 | | - case "txt": |
76 | | - contentType = "text/plain"; |
77 | | - report.ExportToText(ms); |
78 | | - break; |
79 | | - case "csv": |
80 | | - contentType = "text/plain"; |
81 | | - report.ExportToCsv(ms); |
82 | | - break; |
83 | | - case "png": |
84 | | - contentType = "image/png"; |
85 | | - report.ExportToImage(ms, new ImageExportOptions() { Format = System.Drawing.Imaging.ImageFormat.Png }); |
86 | | - break; |
87 | | - } |
88 | | - return File(ms.ToArray(), contentType); |
89 | | - } |
90 | | - } |
91 | | - } |
92 | | -} |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Diagnostics; |
| 4 | +using System.IO; |
| 5 | +using System.Linq; |
| 6 | +using System.Threading.Tasks; |
| 7 | +using DevExpress.XtraPrinting; |
| 8 | +using DevExpress.XtraReports.UI; |
| 9 | +using ServerApp.Model; |
| 10 | +using ServerApp.PredefinedReports; |
| 11 | +using Microsoft.AspNetCore.Mvc; |
| 12 | + |
| 13 | +namespace ServerApp.Controllers |
| 14 | +{ |
| 15 | + [Route("api/[controller]")] |
| 16 | + public class HomeController : Controller |
| 17 | + { |
| 18 | + public IActionResult Index() |
| 19 | + { |
| 20 | + return View(); |
| 21 | + } |
| 22 | + |
| 23 | + public IActionResult Error() |
| 24 | + { |
| 25 | + ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier; |
| 26 | + return View(); |
| 27 | + } |
| 28 | + [HttpGet("[action]")] |
| 29 | + public async Task<object> Print() |
| 30 | + { |
| 31 | + var report = new TestReport(); |
| 32 | + using (var ms = new MemoryStream()) |
| 33 | + { |
| 34 | + await report.ExportToPdfAsync(ms, new DevExpress.XtraPrinting.PdfExportOptions { ShowPrintDialogOnOpen = true }); |
| 35 | + return File(ms.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf); |
| 36 | + } |
| 37 | + } |
| 38 | + [HttpGet("[action]")] |
| 39 | + public ActionResult Export(string format = "pdf") |
| 40 | + { |
| 41 | + format = format.ToLower(); |
| 42 | + XtraReport report = new TestReport(); |
| 43 | + string contentType = string.Format("application/{0}", format); |
| 44 | + using (MemoryStream ms = new MemoryStream()) |
| 45 | + { |
| 46 | + switch (format) |
| 47 | + { |
| 48 | + case "pdf": |
| 49 | + contentType = "application/pdf"; |
| 50 | + report.ExportToPdf(ms); |
| 51 | + break; |
| 52 | + case "docx": |
| 53 | + contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; |
| 54 | + report.ExportToDocx(ms); |
| 55 | + break; |
| 56 | + case "xls": |
| 57 | + contentType = "application/vnd.ms-excel"; |
| 58 | + report.ExportToXls(ms); |
| 59 | + break; |
| 60 | + case "xlsx": |
| 61 | + contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; |
| 62 | + report.ExportToXlsx(ms); |
| 63 | + break; |
| 64 | + case "rtf": |
| 65 | + report.ExportToRtf(ms); |
| 66 | + break; |
| 67 | + case "mht": |
| 68 | + contentType = "message/rfc822"; |
| 69 | + report.ExportToMht(ms); |
| 70 | + break; |
| 71 | + case "html": |
| 72 | + contentType = "text/html"; |
| 73 | + report.ExportToHtml(ms); |
| 74 | + break; |
| 75 | + case "txt": |
| 76 | + contentType = "text/plain"; |
| 77 | + report.ExportToText(ms); |
| 78 | + break; |
| 79 | + case "csv": |
| 80 | + contentType = "text/plain"; |
| 81 | + report.ExportToCsv(ms); |
| 82 | + break; |
| 83 | + case "png": |
| 84 | + contentType = "image/png"; |
| 85 | + report.ExportToImage(ms, new ImageExportOptions() { Format = System.Drawing.Imaging.ImageFormat.Png }); |
| 86 | + break; |
| 87 | + } |
| 88 | + return File(ms.ToArray(), contentType); |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | +} |
0 commit comments