FastReport報表MVC顯示步驟


FastReport報表MVC使用步驟如下:

1、創建MVC網站項目

最終DEMO如下圖所示

 

2、引用相關DLL

FastReport.dll

FastReport.Web.dll

3、Web.config中增加配置

<system.webServer>
    <handlers>
        <add name="FastReport-Export" path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport" />
    </handlers>
</system.webServer>

4、Action代碼

 1     public class HomeController : Controller
 2     {
 3         public ActionResult Index()
 4         {
 5             var webReport = new WebReport();
 6 
 7             var dataPath= Server.MapPath("~/frAssets/Reports/nwind.xml");
 8             var dataSet = new System.Data.DataSet();
 9             dataSet.ReadXml(dataPath);
10             webReport.Report.RegisterData(dataSet, "NorthWind");
11 
12             var reportPath = Server.MapPath("~/frAssets/Reports/SimpleList.frx");
13             webReport.Report.Load(reportPath);
14 
15             webReport.Width = Unit.Percentage(100);
16             webReport.Height = Unit.Percentage(100);
17             //設置Toobar圖標樣式
18             webReport.ToolbarIconsStyle = ToolbarIconsStyle.Black;//ToolbarIconsStyle.Custom;
19             //設置Background樣式
20             webReport.ToolbarBackgroundStyle = ToolbarBackgroundStyle.Medium;
21             //設置自定義按鈕圖片路徑
22             webReport.ButtonsPath = "/frAssets/Buttons/";
23             //本地化文件
24             webReport.LocalizationFile = "/frAssets/Localization/Chinese (Simplified).frl";
25             webReport.PrintInPdf = false;
26             ViewBag.WebReport = webReport;
27             return View();
28         }
29         
30     }

5、View中引入樣式

1 @WebReportGlobals.Scripts()
2 @WebReportGlobals.Styles()

 

6、View中添加報表呈現代碼

1 <div id="report-wrapper">
2     @ViewBag.WebReport.GetHtml()
3 </div>

 

7、報表居中樣式處理

    <style type="text/css">
        html > /**/ body .container {
            margin: 0;
            max-width: 100%;
        }

        #report-wrapper .frtoolbar {
            width: 100%;
        }

        #report-wrapper #frbody {
            text-align: center;
        }

            #report-wrapper #frbody > div {
                margin: 0 auto;
            }

        html > /**/ body #report-wrapper span > div > div {
            display: block;
            text-align: center;
        }
    </style>

 

8、項目Demo源碼

https://files.cnblogs.com/files/WangHuaiSheng/FastReportMvcDemo.7z

 

 


 文章作者:花生(OutMan)

發布地址:http://www.cnblogs.com/WangHuaiSheng/ 

發布時間:2018年3月15日

本文版權歸作者和博客園共有,歡迎轉載,

但未經作者同意必須保留此段聲明,

且在文章頁面明顯位置給出原文連接。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM