具体实现代码如下:
- private void button1_Click(object sender, EventArgs e)
- {
- try {
- var combiner = new GrapeCity.ActiveReports.ReportsCore.Tools.ReportCombiner();
- var rpt1 = new GrapeCity.ActiveReports.PageReport();
- rpt1.Load(new System.IO.FileInfo(@"..\..\Report1.rdlx"));
- var rpt2 = new GrapeCity.ActiveReports.PageReport();
- rpt2.Load(new System.IO.FileInfo(@"..\..\Report2.rdlx"));
-
- combiner.SetMargin("0cm");
- combiner.DefaultStep = "0cm";
- combiner.AddReport(rpt1);
- 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.
- //combine reports
- combiner.Mode = GrapeCity.ActiveReports.ReportsCore.Tools.CombineMode.ReportSections;
- GrapeCity.ActiveReports.Document.PageDocument document = new GrapeCity.ActiveReports.Document.PageDocument(combiner.BuildReport());
- document.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(Document_LocateDataSource);
- System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@".");
- outputDirectory.Create();
- GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
- // Set the rendering extension and render the report.
- GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
- GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension("AAA"));
- document.Render(pdfRenderingExtension, outputProvider, pdfSetting);
- }
- catch(Exception ex)
- {
- throw new Exception(ex.ToString());
- }
- }
复制代码 直接对合并后的报表做运行时数据源分配。然后可以在数据源里面,将所有用到的数据集名称都判断一下,然后赋值数据即可
|