zoukankan      html  css  js  c++  java
  • ActiveReports中如何在后台导出运行时绑定数据源报表

    ActiveReports支持运行时绑定数据源功能,这种绑定数据源方法使用较为普及,然而很多系统中都需要在后台导出报表文件,所以用户就很困惑,ActiveReports中如何在后台导出运行时绑定数据源报表?到底是怎样的逻辑?

    这篇文章就主要讲解了在MVC中导出运行时数据源的报表文件。

    1. 新建MVC 工程

    2. 在Index.cshtml 中初始化HTML5Viewer

    <div>
        <div id="viewerContainer" style="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. 新建报表文件【客户信息.rdlx】,并设置数据源为Object Provider

    image

    添加数据集,设置数据集字段

    image

    3. 新建Web服务文件,继承GrapeCity.ActiveReports.Web.ReportService

    重写OnCreateReportHandler方法,实现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中调用导出Excel函数

     void Document_LocateDataSource(object sender, LocateDataSourceEventArgs args)
            {
               
                        string customerID = args.Report.Parameters[0].CurrentValue.ToString();
                        args.Data = GetCustomer(customerID);
                        ExportToExcel(args.Report);
                  
                  
             
            }

    5. 实现导出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下载:

  • 相关阅读:
    幸福之路
    mysql8.0.25安装配置教程(windows 64位)
    解决git@gitee.com: Permission denied (publickey).
    python路径拼接os.path.join()函数的用法
    如何正确的看待Python里的GIL锁
    安装激活Golang
    Django的Orm操作数据库
    爬虫技术栈点
    Django
    Python/数据库/Django笔记
  • 原文地址:https://www.cnblogs.com/lenkaguo/p/5949526.html
Copyright © 2011-2022 走看看