找回密码
 立即注册

QQ登录

只需一步,快速开始

zhubin

初级会员

37

主题

102

帖子

347

积分

初级会员

积分
347
zhubin
初级会员   /  发表于:2023-11-6 15:41  /   查看:1201  /  回复:3
10金币
使用 ReportCombiner 合并多个报表时,参照此例子可以实现


但是如果此时报表使用的是动态数据源,需要使用  _comBinerReport.Document.LocateDataSource 给数据时,如果存在A,B二个报表,怎么给数据,因为每个报表需要一个独立的DataTable
附件: 您需要 登录 才可以下载或查看,没有帐号?立即注册

最佳答案

查看完整内容

具体实现代码如下: 直接对合并后的报表做运行时数据源分配。然后可以在数据源里面,将所有用到的数据集名称都判断一下,然后赋值数据即可

3 个回复

倒序浏览
最佳答案
最佳答案
Felix.LiWyn认证
超级版主   /  发表于:2023-11-6 15:42:00
来自 4#
具体实现代码如下:

  1. private void button1_Click(object sender, EventArgs e)
  2.         {

  3.             try {
  4.                 var combiner = new GrapeCity.ActiveReports.ReportsCore.Tools.ReportCombiner();

  5.                 var rpt1 = new GrapeCity.ActiveReports.PageReport();
  6.                 rpt1.Load(new System.IO.FileInfo(@"..\..\Report1.rdlx"));

  7.                 var rpt2 = new GrapeCity.ActiveReports.PageReport();
  8.                 rpt2.Load(new System.IO.FileInfo(@"..\..\Report2.rdlx"));
  9.                
  10.                 combiner.SetMargin("0cm");
  11.                 combiner.DefaultStep = "0cm";
  12.                 combiner.AddReport(rpt1);
  13.                 combiner.AddReport(rpt2, new LocationOptions() { PageBreakBefore = true, Gap = "5in" }); //adds second report after a page break and a 5 inch gap from the first report. By default this gap is 1 inch.

  14.                 //combine reports
  15.                 combiner.Mode = GrapeCity.ActiveReports.ReportsCore.Tools.CombineMode.ReportSections;

  16.                 GrapeCity.ActiveReports.Document.PageDocument document = new GrapeCity.ActiveReports.Document.PageDocument(combiner.BuildReport());
  17.                 document.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(Document_LocateDataSource);
  18.                 System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@".");
  19.                 outputDirectory.Create();
  20.                 GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();

  21.                 // Set the rendering extension and render the report.
  22.                 GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
  23.                 GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension("AAA"));

  24.                 document.Render(pdfRenderingExtension, outputProvider, pdfSetting);
  25.             }
  26.             catch(Exception ex)
  27.             {
  28.                 throw new Exception(ex.ToString());
  29.             }


  30.         }
复制代码
直接对合并后的报表做运行时数据源分配。然后可以在数据源里面,将所有用到的数据集名称都判断一下,然后赋值数据即可
回复 使用道具 举报
zhubin
初级会员   /  发表于:2023-11-6 15:43:21
2#
另外 _combiner.AddReport 加入的 PageReport 设置数据是无效的,已经有试过
回复 使用道具 举报
Felix.LiWyn认证
超级版主   /  发表于:2023-11-6 18:30:00
3#
问题描述:

报表合并,运行时数据源测试问题

问题待测:您好,这个问题我们本地需要测试一下,如果复现,会回复您
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部