【问题标题】:RDLC Local report viewer for ASP.NET Core and Angular(>2.0)用于 ASP.NET Core 和 Angular(>2.0) 的 RDLC 本地报表查看器
【发布时间】:2018-03-15 21:48:30
【问题描述】:

有没有办法在 asp.net 核心网页中显示 RDLC Local ReportViewer 控件?

要在传统的 WebForms 应用程序上显示 ReportViewer,下面的代码可以工作。

<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

        <div style="height: 600px;">
            <rsweb:ReportViewer ID="reportViewer" runat="server" Width="100%" Height="100%"></rsweb:ReportViewer>
        </div>
    </form>
</body>

我已经尝试并测试了以下组件。结果如下。

  1. ReportViewerForMvc - 适用于 MVC,但与 ASPNET Core 不兼容。
  2. MvcReportViewer - 适用于 MVC,但与 ASPNET Core 不兼容(请参阅此问题:https://github.com/ilich/MvcReportViewer/issues/121)。
  3. MvcReportViewer - 不使用 microsoft 查看器控件,因此支持 aspnet 核心,但不适用于本地报表(需要报表服务器 url)。
  4. ngx-ssrs-reportviewer npm 包 - 远程报告的包装器,不支持本地报告。(需要报告服务器 url)

第一季度。在 asp.net 核心应用程序中使用 &lt;rsweb:ReportViewer&gt; 的最佳方法是什么?

【问题讨论】:

  • 投反对票的人,请告诉我为什么投反对票?我应该能够相应地更新问题。
  • 1.问题是什么? 2. 如果你也要求类似的,那是题外话。阅读this,了解如何提出热点问题
  • @Tseng :我已经改写了这个问题。希望现在清楚了。
  • 简短回答,临睡前:ASP.NET Core 中没有控件,也没有 aspx。如果您真的依赖它,请坚持使用 ASP.NET MVC5,直到您的所有依赖项都可用于 .NET Standard/ASP.NET Core
  • 问题主要是关于“如何在 aspnet 核心项目上使用 microsoft report viewer”。实现细节肯定会有所不同

标签: angular reporting-services asp.net-core pdfjs report-viewer2016


【解决方案1】:

Microsoft 没有在 aspnet 核心中实现或引入 RDLC 报告查看器。相反,他们正在购买产品来填补空白。

新闻的完整链接 - https://blogs.msdn.microsoft.com/sqlrsteamblog/2018/04/02/microsoft-acquires-report-rendering-technology-from-forerunner-software/

链接到原始问题 - https://github.com/aspnet/Home/issues/1528

这里是精华。 "微软从 Forerunner Software 收购报表渲染技术

我们很高兴地宣布,我们从 Forerunner Software 获得了技术,以加快我们对 Reporting Services 的投资。除其他外,该技术包括 Reporting Services (*.rdl) 报告的客户端呈现、用于查看报告的响应式 UI 小部件以及用于将报告集成到其他应用程序的 JavaScript SDK——这证明了我们的合作伙伴可以在此基础上实现的目标我们的开放平台。

这对您来说是个好消息,因为我们看到了将这项技术应用于我们从您那里听到的多个反馈点的机会:

您正在寻找可以运行 SSRS 报告的云软件即服务 (SaaS) 或平台即服务 (PaaS)。正如您可能在我们的 Spring '18 发行说明中看到的那样,我们正在积极致力于将 SSRS 报告引入 Power BI 云服务,并且我们正在构建客户端渲染以实现这一目标。 你想在手机上查看 SSRS 报告,可能使用 Power BI 应用。我们相信这项技术将帮助我们提供更好、响应更快的 UI,以提供报告参数值、在报告中导航,甚至可能查看报告内容。

您喜欢 Report Viewer 控件……但它是一个 ASP.NET Web 窗体控件。你需要一些可以集成到 ASP.NET Core/MVC 应用程序或非 ASP.NET 应用程序中的东西。借助这项技术,我们希望提供一个客户端/基于 JavaScript 的报表查看器,您可以将其集成到任何现代应用程序中。

这些都是艰巨的任务,我们还没有时间表可以分享,但请继续关注接下来的几个月,因为我们始终努力与您分享我们的进展,并尽可能早且经常地听取您的反馈。

Forerunner Software 将在有限的时间内继续为现有客户提供支持。”

【讨论】:

    【解决方案2】:

    为了让 Jame 的解决方案发挥作用 - 它要求您参考完整的 .NET Framework。这对于 ASP.NET Core 1 和 2 来说都很好,但是 - 正如现在每个人都应该知道的那样 - ASP .NET 3 将不允许允许您引用完整的 .NET Framework。

    目前,只能将 SSRS 托管服务器报告 (RDL) 报告与 .NET Core 一起使用。对于客户端 RDLC 报告,目前只有付费的 Syncfusion 解决方案有效(我已经测试了试用版)

    James 解决方案在 ASP.NET Core 3 中完全无效(同样 - 只允许您引用 .NET Core - 而不是 .NET Framework)

    【讨论】:

      【解决方案3】:

      如果问题是如何在 ASP.NET Core 项目上使用 Microsoft Reportviewer,不管实现细节如何,我的解决方案是绕过实际的 reportviewer 控件,直接将报告呈现为 PDF 或 Excel。 它适用于 .net Core 1.1。我们使用的 NuGet 包是Microsoft.ReportViewer.2012.Runtime by Fornax

      using System.IO;
      using Microsoft.AspNetCore.Mvc;
      using Microsoft.Reporting.WebForms;
      
      namespace WebApplication3.Controllers
      {
          public class ReportController : Controller
          {
              private readonly IHostingEnvironment environment = null;
              public ReportController(IHostingEnvironment environment)
              {
                  this.environment = environment;
              }
              public IActionResult Report()
              {
                  string mimeType;
                  string encoding;
                  string filenameExtension;
                  string[] streams;
                  Warning[] warnings;
                  var rv = new ReportViewer();
                  rv.ProcessingMode = ProcessingMode.Local;
                  rv.LocalReport.ReportPath = Path.Combine(environment.ContentRootPath, "Reports", "Report1.rdlc");
                  rv.LocalReport.Refresh();
                  var bytes = rv.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streams, out warnings);
                  return File(bytes, mimeType);
              }
          }
      }
      

      【讨论】:

      • 谢谢。我最终沿着你建议的路线走了。我在这里写了一个关于我的经历的小要点。 gist.github.com/codehippie1/d44701c48df252f30888c5cbcddd6fbe
      • 要点让位于这个包。可能对尝试这条路线的人有用。 npmjs.com/package/ng2-pdfjs-viewer
      • 大家好。快速提问:您的目标是 net core 2.1 还是完整的网络?我问的原因是因为目标网络核心不会构建,因为它说它需要来自 System.Web 的 IDataSource。我已经尝试针对完整的网络平台,但如果我使用 NLog 进行日志记录,它仍然无法正常工作(不知道为什么)......
      • 该示例在 .net Core 1.1 MVC 应用程序中工作,但我们已在具有 .net Core MVC 和 .net 4.6 库但没有 System.Web 的解决方案中实现它。它仍然可以正常编译和执行,但是为了将基于 C# 类的数据集添加到报告中,我们需要将 RDLC 临时移动到引用 System.Web 的 .net MVC 项目中。
      • 但是如果直接生成PDF,怎么布局呢?
      【解决方案4】:

      找到一个npm包ng2-pdfjs-viewer,虽然它不是MS报告查看器,如果你愿意使用PDFJS,包的文档有一个类似的例子使用 LocalReport 查看器生成 pdf 和 ng2-pdfjs-viewer 在浏览器中显示 - (https://www.npmjs.com/package/ng2-pdfjs-viewer)

      <!-- your.component.html -->
      <button (click)="openPdf();">Open Pdf</button>
      
      <!-- your.component.ts-->
      export class MyComponent implements OnInit {
        @ViewChild('pdfViewer') pdfViewer
        ...
       
        private downloadFile(url: string): any {
          return this.http.get(url, { responseType: ResponseContentType.Blob }).map(
            (res) => {
              return new Blob([res.blob()], { type: "application/pdf" });
            });
        }
       
        public openPdf() {
          let url = "http://localhost:4200/api/GetMyPdf";
          this.downloadFile(url).subscribe(
          (res) => {
              this.pdfViewer.pdfSrc = res; // pdfSrc can be Blob or Uint8Array
              this.pdfViewer.refresh(); // Ask pdf viewer to load/reresh pdf
            }
          );
        }
      
      [HttpGet]
      [Route("MyReport")]
      public IActionResult GetReport()
      {
         var reportViewer = new ReportViewer {ProcessingMode = ProcessingMode.Local};
         reportViewer.LocalReport.ReportPath = "Reports/MyReport.rdlc";
       
         reportViewer.LocalReport.DataSources.Add(new ReportDataSource("NameOfDataSource1", reportObjectList1));
         reportViewer.LocalReport.DataSources.Add(new ReportDataSource("NameOfDataSource2", reportObjectList1));
       
         Warning[] warnings;
         string[] streamids;
         string mimeType;
         string encoding;
         string extension;
       
         var bytes = reportViewer.LocalReport.Render("application/pdf", null, out mimeType, out encoding, out extension, out streamids, out warnings);
       
         return File(bytes, "application/pdf")
      }
      

      【讨论】:

      • 您好!您在此处引用了哪些程序集?
      • libaray 指的是哪个?
      【解决方案5】:
      public List<object> _dataSourceList = new List<object>();
      public string _dataSourceName { get; set; }
      
      public string _reportPath = CommonUtil.Report_path; //set your report path in app.config file
      public Dictionary<string, string> Parameters = new Dictionary<string, string>();
      
      public void PDFPrint_Load() {
      
        string mimtype="";
        int extension = 1;
      
        LocalReport localReport= new LocalReport(_reportPath);
        localReport.AddDataSource(_dataSourceName, _dataSourceList);
      
        if (Parameters != null && Parameters.Count > 0)// if you use parameter in report
        {
          List<ReportParameter> reportparameter = new List<ReportParameter>();
          foreach (var record in Parameters) {
            reportparameter.Add(new ReportParameter());
          }
        }
        var result = localReport.Execute(RenderType.Pdf, extension,parameters: 
        Parameters, mimtype);
      
        byte[] bytes = result.MainStream;
        string fileName = "Report.pdf";
        return File(bytes , "application/pdf",fileName );
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-29
        • 1970-01-01
        相关资源
        最近更新 更多