找回密码
 立即注册

QQ登录

只需一步,快速开始

893559686

初级会员

13

主题

40

帖子

345

积分

初级会员

积分
345

微信认证勋章

893559686
初级会员   /  发表于:2016-9-21 16:16  /   查看:3747  /  回复:7
本帖最后由 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










7 个回复

倒序浏览
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2016-9-21 17:11:06
沙发
您好,如果您想针对多个RDL报表导出到一个pdf文件中,只需要在后台将报表导出PDF文件后,合并PDF文件即可,
详细代码:

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

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

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

  13.     FileInfo myFile1 = new FileInfo(exportFileRdlx);

  14.     // Export the report to PDF and merge the other PDF files into it.  
  15.     PdfRenderingExtension pdfRenderingExtension = new PdfRenderingExtension();
  16.     FileStreamProvider _outputProvider = new FileStreamProvider(myFile1.Directory, myFile1.Name);
  17.     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之后或之前:



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

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

  7.             reportDocument.Render(pdfRenderingExtension, outputProvider, pdfSetting);
  8.    









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

  16.             reportDocument1.Render(pdfRenderingExtension1, outputProvider1, pdfSetting1);
  17.             reportDocument1.Dispose();
复制代码


回复 使用道具 举报
893559686
初级会员   /  发表于:2016-9-22 16:04:40
5#
本帖最后由 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
6#
这可能是在动态加载数据源的时候,数据库连接比较耗时吧~
回复 使用道具 举报
893559686
初级会员   /  发表于:2016-9-23 09:16:42
7#
Lenka.Guo 发表于 2016-9-22 18:00
这可能是在动态加载数据源的时候,数据库连接比较耗时吧~

这个应该不会,程序一开始已经将报表所有的数据加载出来了,在导出报表的时候,报表数据源是从内存中读取的。
觉得可能是在导出过程中不断的加载报表导致的,抽空在调试下吧。谢啦。
回复 使用道具 举报
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2016-9-23 10:12:12
8#
893559686 发表于 2016-9-23 09:16
这个应该不会,程序一开始已经将报表所有的数据加载出来了,在导出报表的时候,报表数据源是从内存中读取 ...

辛苦了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部