Merge Reports

A report may include pages that do not fit an entire report template, for example, a title page, charts within a table report, pages with an alternative orientation or specific pages at the end of a report. Report Merging enables you to add such pages by merging pages you created in a separate report with the base report. It also allows you to print and export merged pages as a single document while preserving the original reports' page settings and orientation.

report-merging

Tip

When merging reports that include a large amount of data, use the CachedReportSource/CachedReportSourceWeb object. Refer to the Merge Large Reports topic for details.

Tip

When you merge reports in eXpressApp Framework applications, follow the instructions given in the How to: Merge the Pages of Two Reports topic.

Report Merging Overview

To merge reports, generate report documents by calling the XtraReport.CreateDocument method and put report pages in a specific order using the XtraReport.ModifyDocument method.

using DevExpress.XtraReports.UI;
// ...

private void CombineTwoReports() {
    // Create the 1st report and generate its document.
    XtraReport1 report1 = new XtraReport1();
    report1.CreateDocument();

    // Create the 2nd report and generate its document.
    XtraReport2 report2 = new XtraReport2();
    report2.CreateDocument();

    // Add all pages of the 2nd report to the end of the 1st report.
    report1.ModifyDocument(x => {
        for (int i = 0; i < report2.Pages.Count; i++) {
            x.InsertPage(x.PageCount, report2.Pages[i]);
        };
    });

    // Reset all page numbers in the resulting document.
    report1.PrintingSystem.ContinuousPageNumbering = true;

    // Preview the modified report.
    //...
}

Alternatively, you can handle a report's XRControl.AfterPrint event, which is raised after a document for the report is generated.

using System;
// ...

private void XtraReport1_AfterPrint(object sender, EventArgs e) {   
    //Create the 2nd report and generate its document.
    XtraReport2 report2 = new XtraReport2();
    report2.CreateDocument();

    // Enable this property to maintain continuous page numbering
    PrintingSystem.ContinuousPageNumbering = true;

    // Add all pages of the 2nd report to the end of the 1st report.
    ModifyDocument(x => {
        for (int i = 0; i < report2.Pages.Count; i++) {
            x.InsertPage(x.PageCount, report2.Pages[i]);
        };
    });        
}

You can update the page numbers or preserve the original page numbers using the PrintingSystemBase.ContinuousPageNumbering property if you have pages numbered in the base report.

Tip

Do not dispose of the merged documents before publishing the resulting document (the resulting document does not create a "deep copy" of merged documents).

Limitations

The following limitations apply to merged documents when previewing them:

  • Document exporting in continuous (single file) mode is not supported. As a workaround, you can use subreports to display multiple reports in a single document, or you can export individual documents to separate files and then manually combine them into a single file.
  • Interactive features are not supported because they require rebuilding the document (for instance, the drill-down functionality, sorting, report parameters input).
  • Page setup is not available.