ActiveReports 18 .NET Edition
Developers / Working with Reports / Page/RDLX Report / Merge Multiple Reports
In This Topic
    Merge Multiple Reports
    In This Topic

    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. 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:

     Combine Three Reports

    Visual Basic.NET. Paste inside Form1_Load event.
    Copy Code
    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"
    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)
    
    '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")
    
    Viewer1.LoadDocument(combiner.BuildReport().Document)   'load combined report in viewer
    combiner.BuildReport().Document.Render(pdfRe, provider) 'export combined report in PDF format
    

    C# code
    Copy Code
    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";
    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);    
    
    //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");
    
    viewer1.LoadDocument(combiner.BuildReport().Document);   //load combined report in viewer
    combiner.BuildReport().Document.Render(pdfRe, provider); //export combined report in PDF format
    

    The merged reports can be modified in many ways as described below.

    Add reports at particular index

    If you want to add a report r4 after the first report r1, use the following code with index '1':

    C#
    Copy Code
    combiner.Insert(1, r4, new LocationOptions());
    report = combiner.BuildReport();
    
    VB.NET
    Copy Code
    combiner.Insert(1, r4, New GrapeCity.ActiveReports.ReportsCore.Tools.LocationOptions())
    report = combiner.BuildReport()
    

    Add a list of reports

    C#
    Copy Code
    combiner.AddRange(new PageReport[] {r1, r2, r3, r4 }, new LocationOptions())
    report = combiner.BuildReport();
    
    VB.NET
    Copy Code
    Dim reports As IEnumerable(Of GrapeCity.ActiveReports.PageReport) = {r1, r2, r3, r4}
    combiner.AddRange(reports, New GrapeCity.ActiveReports.ReportsCore.Tools.LocationOptions())
    report = combiner.BuildReport()
    

    Delete report(s)

    If you want to delete a report in first position, use the following code with index '0':

    C#
    Copy Code
    combiner.RemoveAt(0);
    report = combiner.BuildReport();
    
    VB.NET
    Copy Code
    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:

    C#
    Copy Code
    combiner.RemoveAll(r2);
    report = combiner.BuildReport();
    
    VB.NET
    Copy Code
    combiner.RemoveAll(r2)
    report = combiner.BuildReport()
    

    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.