许多FastReport.Core用户都对报表生成器如何在使用React库编写的Web应用程序中工作感兴趣。在本文中,我们将介绍使用在线设计器的方法。尽管它与常规报表显示在同一个Web对象中,但与React中显示的差异很大。
如果您从未在React上使用.Net Core上的后端创建应用程序,那么您需要:
1)安装NodeJS。这是一个软件包,允许您在服务器端执行JavaScript代码,以及安装各种JavaScript库。
2)安装Microsoft Visual Studio 2017或其他IDE + .Net Core SDK 2.0。
要创建应用程序,请在项目所在的文件夹中打开Windows命令提示符,然后执行以下命令:
dotnet new react -o ReactFRCoreDesigner
打开创建的项目。让我们将FastReport库添加到NuGet包管理器中。配置文件夹的本地包源:
C: Program Files(x86) FastReports FastReport.Net Nugets
安装FastReport.Core包。
在项目中找到Startup.cs文件,并在Configure()方法中添加一行代码:
app.UseFastReport();
现在我们可以在项目中使用报表生成器。
除了显示在线设计器之外,我们还会查看传输所需报表名称的方式,并将其上传到在线设计器。因此,我们将App_Data文件夹添加到项目中。在其中,我们将从FR.Net安装目录中的Demos Reports文件夹添加报表模板。
如您所见,我们还从同一文件夹中添加了一个xml文件。这是一个报告数据库。
找到Controllers文件夹。我们可以使用SampleDataController控制器。添加两个方法:
…using FastReport.Web;using System.IO;…[HttpGet("[action]")] public IActionResult Design(string name) { WebReport WebReport = new WebReport(); WebReport.Width = "1000"; WebReport.Height = "1000"; if (name != "Blank") WebReport.Report.Load("App_Data/" + name + ".frx"); // Load the report into the WebReport object System.Data.DataSet dataSet = new System.Data.DataSet(); // Create a data source dataSet.ReadXml("App_Data/nwind.xml"); // Open the database xml WebReport.Report.RegisterData(dataSet, "NorthWind"); // Registering the data source in the report WebReport.Mode = WebReportMode.Designer; // Set the web report object mode - designer display WebReport.DesignerLocale = "en"; WebReport.DesignerPath = @"WebReportDesigner/index.html"; // We set the URL of the online designer WebReport.DesignerSaveCallBack = @"api/SampleData/SaveDesignedReport"; // Set the view URL for the report save method WebReport.Debug = true; ViewBag.WebReport = WebReport; // pass the report to View return View(); } [HttpPost("[action]")] // call-back for save the designed report public IActionResult SaveDesignedReport(string reportID, string reportUUID) { ViewBag.Message = String.Format("Confirmed {0} {1}