ActiveReports 14 .NET Edition
ActiveReports 14 User Guide / How To / Page Report/RDL Report How To / Page/RDL Report Scenarios / Merge Multiple Reports
In This Topic
    Merge Multiple Reports
    In This Topic

    You can merge or combine multiple Page and RDL reports into one report. Merging is performed by using ReportCombiner class which adds the reports as subreports. The reports are merged one after the another, in the order in which they are added. To correctly combine reports, you should use reports with the same layouts: for Page reports, you need to set equal margins for all reports and for RDL reports, you need to set equal margins and width for all 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 combines three reports. You need to add GrapeCity.ActiveReports.Core.Rendering assembly to your project. The code also exports the merged report in PDF format, so you need to add GrapeCity.ActiveReports.Export.Pdf assembly.

    To write the code in Visual Basic.NET

    Visual Basic.NET
    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.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
    

    To write the code in C#

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

    To 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()
    

    To 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()
    

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