原創(chuàng)|使用教程|編輯:王香|2018-07-31 15:17:39.000|閱讀 263 次
概述:本文介紹了如何使用FastReport.Net 2018新功能:nuget數(shù)據(jù)包
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
FastReport.Net 2018新功能之一:使用nuget數(shù)據(jù)包,要安裝軟件包,必須創(chuàng)建一個本地軟件包源并將已編譯的FastReport庫放在其中(對于授權(quán)的軟件包,此機(jī)制已保留)。
創(chuàng)建.Net Core應(yīng)用程序,調(diào)用解決方案的上下文菜單,然后選擇Manage NuGet Packages項(xiàng)。
選擇Packages source——nuget.org,在搜索欄中鍵入FastReport。
用戶需要安裝兩個軟件包:FastReport.Core和FastReport.Web。
第一個是.Net Core框架的實(shí)際FastReport庫,第二個是WebReport對象,允許用戶在瀏覽器中顯示報表并對其進(jìn)行管理。
要在應(yīng)用程序中顯示報表,需要一個報表文件。從FastReport.Net中獲取Master-Detail.frx報告模板和nwind.xml數(shù)據(jù)庫文件,將它們放在Reports文件夾中,先在wwwroot的根目錄中創(chuàng)建它:
打開HomeController類
需要一個接口IHostEnviroment,使用它獲取有關(guān)環(huán)境的信息,具體來說,需要WebRootPath屬性來指定報表文件和數(shù)據(jù)庫的路徑。因此,添加一個類的構(gòu)造函數(shù),該類將接口作為參數(shù)。
private readonly IHostingEnvironment _hostingEnvironment; public HomeController(IHostingEnvironment hostingEnvironment) { _hostingEnvironment = hostingEnvironment; }
在Index方法中,編寫以下代碼:
public IActionResult Index() { string webRootPath = _hostingEnvironment.WebRootPath; // Get the path to the wwwroot folder WebReport webReport = new WebReport(); // Create a Web Report Object webReport.Report.Load(webRootPath + "/reports/Master-Detail.frx"); // Load the report into the WebReport object var dataSet = new DataSet(); // Create a data source dataSet.ReadXml(webRootPath + "/reports/nwind.xml"); // Open the xml database webReport.Report.RegisterData(dataSet, "NorthWind"); // Register the data source in the report ViewBag.WebReport = webReport; return View(); }
要在網(wǎng)頁上顯示W(wǎng)ebReport對象,請更改Index.cshtml視圖,如下所示:
@{ ViewData["Title"] = "Home Page"; } @await ViewBag.WebReport.Render();
在Startup.cs文件中,需要進(jìn)行更改,代碼:
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseFastReport(); … }
現(xiàn)在運(yùn)行應(yīng)用程序:
使用FastReport.Core會更加容易,但是,仍然必須從本地源安裝許可包,不過配置NuGet包的本地源只需要一分鐘的時間。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn