當(dāng)前位置:
首頁(yè) >
ActiveReports中如何在后台导出运行时绑定数据源报表
發(fā)布時(shí)間:2025/3/14
28
豆豆
生活随笔
收集整理的這篇文章主要介紹了
ActiveReports中如何在后台导出运行时绑定数据源报表
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
ActiveReports支持運(yùn)行時(shí)綁定數(shù)據(jù)源功能,這種綁定數(shù)據(jù)源方法使用較為普及,然而很多系統(tǒng)中都需要在后臺(tái)導(dǎo)出報(bào)表文件,所以用戶就很困惑,ActiveReports中如何在后臺(tái)導(dǎo)出運(yùn)行時(shí)綁定數(shù)據(jù)源報(bào)表?到底是怎樣的邏輯?
這篇文章就主要講解了在MVC中導(dǎo)出運(yùn)行時(shí)數(shù)據(jù)源的報(bào)表文件。
?
1. 新建MVC 工程
2. 在Index.cshtml 中初始化HTML5Viewer
<div><div id="viewerContainer" style="width:100%;height:800px;border:1px solid gray;margin-top:20px;"></div> </div><script type="text/javascript">$(function () {var viewer = GrapeCity.ActiveReports.Viewer( { element: '#viewerContainer', report: { id: "客戶信息.rdlx" }, reportService: { url: 'ActiveReportsService.asmx' }, uiType: 'desktop' }); }); </script>?
3. 新建報(bào)表文件【客戶信息.rdlx】,并設(shè)置數(shù)據(jù)源為Object Provider
?
添加數(shù)據(jù)集,設(shè)置數(shù)據(jù)集字段
?
3. 新建Web服務(wù)文件,繼承GrapeCity.ActiveReports.Web.ReportService
重寫OnCreateReportHandler方法,實(shí)現(xiàn)LocateDataSource方法
protected override object OnCreateReportHandler(string reportPath){var instance = base.OnCreateReportHandler(reportPath); var pageReport = instance as PageReport; if (pageReport != null) { pageReport.Document.LocateDataSource += Document_LocateDataSource; } return instance; }?
4. 在LocateDataSource中調(diào)用導(dǎo)出Excel函數(shù)
void Document_LocateDataSource(object sender, LocateDataSourceEventArgs args){string customerID = args.Report.Parameters[0].CurrentValue.ToString();args.Data = GetCustomer(customerID);ExportToExcel(args.Report);}5. 實(shí)現(xiàn)導(dǎo)出Excel方法
private void ExportToExcel(PageDocument report){GrapeCity.ActiveReports.Export.Excel.Section.XlsExport xlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();xlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;xlsExport1.Export(report, @"D:\Demo\\" + "\\XLS1t.xlsx");}?
Demo下載:
?
ActiveReports10_Mvc4 (2).zip轉(zhuǎn)載于:https://www.cnblogs.com/lenkaguo/p/5949526.html
總結(jié)
以上是生活随笔為你收集整理的ActiveReports中如何在后台导出运行时绑定数据源报表的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: IO流(五)__文件的递归、Proper
- 下一篇: NCspider项目总结