[]
Multiple RDLX and Page Reports can be merged or combined into one report. The ReportCombiner class is used for performing merging, which adds the reports as subreports or report sections. The ReportSections property (CombineMode enum) is a default property, indicating that the final multi-section report will contain each report as a section. With the SubReports property, marked as obsolete, a final report will have a single body, containing subreports for every merged report.
The reports are merged one after the another, in the order in which they are added. To combine the reports correctly, you should use reports with the same layouts. For Page reports, you need to set equal margins for all reports and for RDLX reports, you need to set equal margins and width for all reports. See Layout topic for more information.
Having access to BuildReport method, user can use full PageReport class functionality. You can add a page break or specify the gap between two reports.
You can use the BuildReport method to utilize all the features of the PageReport class. You can also insert page breaks and specify the gap between two reports when merging. By default, the gap of 1 inch is added between the reports.
The following code examples demonstrate merging reports in different scenarios. You need to add following packages to your project:
Dim combiner = New GrapeCity.ActiveReports.ReportsCore.Tools.ReportCombiner()
Dim r1 = New GrapeCity.ActiveReports.PageReport()
r1.Load(New System.IO.FileInfo("c:\temp\Report1.rdlx"))
Dim r2 = New GrapeCity.ActiveReports.PageReport()
r2.Load(New System.IO.FileInfo("c:\temp\Report2.rdlx"))
Dim r3 = New GrapeCity.ActiveReports.PageReport()
r3.Load(New System.IO.FileInfo("c:\temp\Report3.rdlx"))
combiner.SetMargin("0cm")
combiner.DefaultStep = "0cm"
'Set Combine Mode as ReportSections (default) Or as SubReports (obsolete)
combiner.Mode = GrapeCity.ActiveReports.ReportsCore.Tools.CombineMode.ReportSections
combiner.AddReport(r1)
Dim options = New GrapeCity.ActiveReports.ReportsCore.Tools.LocationOptions
options.Gap = "5in" 'adds a 5 inch gap from the first report. By default this gap is 1 inch.
options.PageBreakBefore = True 'adds a page break.
combiner.AddReport(r2, options)
combiner.AddReport(r3)
'Create and Save Combined/Merged Report
combiner.BuildReport().Save(New System.IO.FileInfo("c:\temp\CombinedReport.rdlx"))
'Load Combined Report in viewer
Viewer1.LoadDocument(combiner.BuildReport().Document)
'PDF Rendering extension
Dim pdfRe = New GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension()
Dim provider = New GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(New System.IO.DirectoryInfo("c:\temp\"), "CombinedReport")
combiner.BuildReport().Document.Render(pdfRe, provider) 'export combined report in PDF format
var combiner = new GrapeCity.ActiveReports.ReportsCore.Tools.ReportCombiner();
var r1 = new GrapeCity.ActiveReports.PageReport();
r1.Load(new System.IO.FileInfo(@"c:\temp\Report1.rdlx"));
var r2 = new GrapeCity.ActiveReports.PageReport();
r2.Load(new System.IO.FileInfo(@"c:\temp\Report2.rdlx"));
var r3 = new GrapeCity.ActiveReports.PageReport();
r3.Load(new System.IO.FileInfo(@"c:\temp\Report3.rdlx"));
combiner.SetMargin("0cm");
combiner.DefaultStep = "0cm";
//Set Combine Mode as ReportSections (default) or as SubReports (obsolete)
combiner.Mode = GrapeCity.ActiveReports.ReportsCore.Tools.CombineMode.ReportSections;
combiner.AddReport(r1);
combiner.AddReport(r2, 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.
combiner.AddReport(r3);
//Create and Save Combined/Merged Report
combiner.BuildReport().Save(new System.IO.FileInfo(@"c:\temp\CombinedReport.rdlx"));
//Load Combined Report in Viewer
viewer1.LoadDocument(combiner.BuildReport().Document);
//PDF Rendering extension
var pdfRe = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
var provider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(new System.IO.DirectoryInfo(@"c:\temp\"), "CombinedReport");
combiner.BuildReport().Document.Render(pdfRe, provider); //export combined report in PDF format
The merged reports can be modified in many ways as described below.
If you want to add a report r4 after the first report r1, use the following code with index '1':
combiner.Insert(1, r4, new LocationOptions());
report = combiner.BuildReport();
combiner.Insert(1, r4, New GrapeCity.ActiveReports.ReportsCore.Tools.LocationOptions())
report = combiner.BuildReport()
combiner.AddRange(new PageReport[] {r1, r2, r3, r4 }, new LocationOptions())
report = combiner.BuildReport();
Dim reports As IEnumerable(Of GrapeCity.ActiveReports.PageReport) = {r1, r2, r3, r4}
combiner.AddRange(reports, New GrapeCity.ActiveReports.ReportsCore.Tools.LocationOptions())
report = combiner.BuildReport()
If you want to delete a report in first position, use the following code with index '0':
combiner.RemoveAt(0);
report = combiner.BuildReport();
combiner.RemoveAt(0)
report = combiner.BuildReport()
Similarly, if you want to delete report at second position, use index '1'.
If you want to delete all instances of report r2, use the following code:
combiner.RemoveAll(r2);
report = combiner.BuildReport();
combiner.RemoveAll(r2)
report = combiner.BuildReport()
type=note
Note:
- If the reports being merged are of different sizes, the page size of the first report is applied to all the pages of combined report.
- If the reports being merged are of different paper orientations, the paper orientation of the first report is applied to all the pages of combined report.