893559686 发表于 2016-9-21 16:16:17

ActiveReport 关于多个不同模板的报表合并问题

本帖最后由 Lenka.Guo 于 2016-9-21 17:11 编辑

求助:                如何将多个不同模板的RDL报表合并成一个报表?

需求:
      导出多个报表到一个pdf文件中。
      因为咨询了一下技术,想要实现多个报表导出到一个pdf文件中,需要将多个RDL报表合并成一个报表,然后再导出到pdf中。

代码如下:

      //aFindCheckedList 包含所有报表数据集和报表路径等信息,需要将这些报表合并到一个报表中,用于导出到一个Pdf 文件中
   foreach (var item in aFindCheckedList)
{            
//报表全路径(路径+报表名称)   
string aPath = Utils.SystemSetting.RegSettings.ReportPath + item.Path + item.FileName;   
PageReport _repPage = new PageReport(new System.IO.FileInfo(aPath));                                                                                                               PageDocument _reportRuntime = new PageDocument(_repPage);
_reportRuntime.LocateDataSource += (send, args) =>   {   
object reportData = null;   
if (item.ReportDataSourceDic != null)
{
//一个报表有多个数据集,根据数据集名称查找对应的数据集         
reportData = item.ReportDataSourceDic.Where(i => i.Key.Equals(args.DataSetName)).FirstOrDefault().Value;   
}
args.Data = reportData;   
};
}
技术给出实现方案了,感谢。

http://blog.gcpowertools.com.cn/post/CombineReport.aspx










Lenka.Guo 发表于 2016-9-21 17:11:06

您好,如果您想针对多个RDL报表导出到一个pdf文件中,只需要在后台将报表导出PDF文件后,合并PDF文件即可,
详细代码:

// C#
    // Create a new page report.
    PageReport _reportDef = new PageReport(new FileInfo(@”..\..\NWindTable.rdlx”));
    PageDocument reportDocument = new PageDocument(_reportDef);

    // Set up the PDF file names and paths.
    string exportFileBefore = Application.StartupPath + @”/../../one.pdf”;
    string exportFileAfter = Application.StartupPath + @”/../../three.pdf”;
    string exportFileRdlx = “merge.pagereports.pdf”;

    // Set up PDF files to merge into the export.
    settings = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
    settings.DocumentToAddBeforeReport = exportFileBefore;
    settings.DocumentToAddAfterReport = exportFileAfter;

    FileInfo myFile1 = new FileInfo(exportFileRdlx);

    // Export the report to PDF and merge the other PDF files into it.
    PdfRenderingExtension pdfRenderingExtension = new PdfRenderingExtension();
    FileStreamProvider _outputProvider = new FileStreamProvider(myFile1.Directory, myFile1.Name);
    reportDocument.Render(pdfRenderingExtension, _outputProvider, settings);

详情参考博客最下面有关于拼接RDL报表:http://blog.gcpowertools.com.cn/post/CombineReport.aspx

893559686 发表于 2016-9-22 09:10:11

本帖最后由 893559686 于 2016-9-22 09:12 编辑

Lenka.Guo 发表于 2016-9-21 17:11
您好,如果您想针对多个RDL报表导出到一个pdf文件中,只需要在后台将报表导出PDF文件后,合并PDF文件即可, ...
您好,请教一下如果是多个路径没有搞懂如何拼接?
PageReport _reportDef = new PageReport(new FileInfo(@"C:\Users\zz\Desktop\批量导出pdf\ExportPdf.rdlx"));            
PageDocument reportDocument = new PageDocument(_reportDef);            
string p1 = @"C:\Users\zz\Desktop\批量导出pdf\TempFile\封面.pdf";            
string p2 = @"C:\Users\zz\Desktop\批量导出pdf\TempFile\编审人员签字页.pdf";            
string p3 = @"C:\Users\zz\Desktop\批量导出pdf\TempFile\编制说明.pdf";         
string p4 = @"C:\Users\zz\Desktop\批量导出pdf\TempFile\变电站技术改造工程总表(表一).pdf";            
string p5 = @"C:\Users\zz\Desktop\批量导出pdf\TempFile\变电站技术改造建筑工程专业汇总表(表二乙).pdf";            
List<string> PList = new List<string>();            
PList.Add(p1);            
PList.Add(p2);            
PList.Add(p3);            
PList.Add(p4);            
PList.Add(p5);            
string aMergePath = @"C:\Users\zz\Desktop\批量导出pdf\MergeReport.pdf";            
FileInfo myFile1 = new FileInfo(aMergePath);            
GrapeCity.ActiveReports.Export.Pdf.Page.Settings settings = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();             settings.DocumentToAddBeforeReport = p1;            
settings.DocumentToAddAfterReport = p2;
                        
???????????????                                                
此处应该如何拼接            


/ Export the report to PDF and merge the other PDF files into it.            
GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();            
FileStreamProvider _outputProvider = new FileStreamProvider(myFile1.Directory, myFile1.Name);            reportDocument.Render(pdfRenderingExtension, _outputProvider, settings);




Lenka.Guo 发表于 2016-9-22 12:07:31

893559686 发表于 2016-9-22 09:10
您好,请教一下如果是多个路径没有搞懂如何拼接?
PageReport _reportDef = new PageReport(new FileInf ...
多个文档,以我的理解就是多次合并您需要重复添加将之前已合并的文件,添加到新生成的reportDocument之后或之前:



            GrapeCity.ActiveReports.Document.PageDocument reportDocument = new GrapeCity.ActiveReports.Document.PageDocument(report);
            GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
            GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
            pdfSetting.DocumentToAddAfterReport = p1;

            FileInfo myfile = new FileInfo(p4);
            GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(myfile.Directory, myfile.Name);

            reportDocument.Render(pdfRenderingExtension, outputProvider, pdfSetting);
   









            GrapeCity.ActiveReports.Document.PageDocument reportDocument1 = new GrapeCity.ActiveReports.Document.PageDocument(report);
            GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting1 = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
            GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension1 = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
            pdfSetting1.DocumentToAddAfterReport = p4;
         
            FileInfo myfile1 = new FileInfo(p5);
            GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider1 = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(myfile1.Directory, myfile1.Name);

            reportDocument1.Render(pdfRenderingExtension1, outputProvider1, pdfSetting1);
            reportDocument1.Dispose();

893559686 发表于 2016-9-22 16:04:40

本帖最后由 893559686 于 2016-9-22 16:09 编辑

Lenka.Guo 发表于 2016-9-22 12:07
多个文档,以我的理解就是多次合并您需要重复添加将之前已合并的文件,添加到新生成的reportDocument之后 ...
感谢您的解答,已经搞定,只是效率比较慢,三张很简单的报表,数据量很小,用了17秒多。能否优化,请您帮忙瞧瞧:


string aMergeNewFullName = @"C:\Users\zz\Desktop\批量导出pdf\MergeReport.pdf";                                                                                                

for (int i = 0; i < aFindCheckedList.Count(); i++)               
{                  
if ((i + 1) > aFindCheckedList.Count) { continue; }                  
string aReportTempFullName = BHNECost.Utils.SystemSetting.RegSettings.ReportPath + aFindCheckedList.Path + aFindCheckedList.FileName;             PageReport _reportDef = new PageReport(new FileInfo(aReportTempFullName));                  
PageDocument reportDocument = new PageDocument(_reportDef);                  
reportDocument.LocateDataSource += (send, args) =>                  
{                        
object reportData = null;                        
if (aFindCheckedList.ReportDataSourceDic != null)                           
      reportData = aFindCheckedList.ReportDataSourceDic.Where(s => s.Key.Equals(args.DataSetName)).FirstOrDefault().Value;                        
args.Data = reportData;                  
};                     

GrapeCity.ActiveReports.Export.Pdf.Page.Settings settings = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();                   settings.DocumentToAddBeforeReport = aMergeNewFullName;                     
aMergeNewFullName = string.Format(@"C:\Users\zz\Desktop\批量导出pdf\MergeReport{0}.pdf", i);         
         
FileInfo myFile1 = new FileInfo(aMergeNewFullName);      
            
// Export the report to PDF and merge the other PDF files into it.                  
GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();                  
FileStreamProvider _outputProvider = new FileStreamProvider(myFile1.Directory, myFile1.Name);                   reportDocument.Render(pdfRenderingExtension, _outputProvider, settings);      
         
}




Lenka.Guo 发表于 2016-9-22 18:00:20

这可能是在动态加载数据源的时候,数据库连接比较耗时吧~

893559686 发表于 2016-9-23 09:16:42

Lenka.Guo 发表于 2016-9-22 18:00
这可能是在动态加载数据源的时候,数据库连接比较耗时吧~

这个应该不会,程序一开始已经将报表所有的数据加载出来了,在导出报表的时候,报表数据源是从内存中读取的。
觉得可能是在导出过程中不断的加载报表导致的,抽空在调试下吧。谢啦。

Lenka.Guo 发表于 2016-9-23 10:12:12

893559686 发表于 2016-9-23 09:16
这个应该不会,程序一开始已经将报表所有的数据加载出来了,在导出报表的时候,报表数据源是从内存中读取 ...

辛苦了
页: [1]
查看完整版本: ActiveReport 关于多个不同模板的报表合并问题