本示例阐明了使用 XtraReport.Pages 属性来解决不同的任务。

下面的代码演示了如何把一个报表的所有页面添加到另一个报表的尾部。

C#CopyCode image复制代码
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.Pages.AddRange(report2.Pages);

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

    // Show the Print Preview form.
    report1.ShowPreviewDialog();
}
Visual BasicCopyCode image复制代码
Private Sub CombineTwoReports()
    ' Create the 1st report and generate its document.
    Dim report1 As XtraReport1 = New XtraReport1()
    report1.CreateDocument()

    ' Create the 2nd report and generate its document.
    Dim report2 As XtraReport2 = New XtraReport2()
    report2.CreateDocument()

    ' Add all pages of the 2nd report to the end of the 1st report.
    report1.Pages.AddRange(report2.Pages)

    ' Reset all page numbers in the resulting document.
    report1.PrintingSystem.ContinuousPageNumbering = True

    ' Show the Print Preview form.
    report1.ShowPreviewDialog()
End Sub

下面的代码演示了如何把两个报表的页面逐页合并到一个报表中。

C#CopyCode image复制代码
private void MergeTwoReports() {
    // 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();

    // Merge pages of two reports, page-by-page.
    int minPageCount = Math.Min(report1.Pages.Count, report2.Pages.Count);
    for (int i = 0; i < minPageCount; i++) {
        report1.Pages.Insert(i * 2 + 1, report2.Pages[i]);
    }
    if (report2.Pages.Count != minPageCount) {
        for (int i = minPageCount; i < report2.Pages.Count; i++) {
            report1.Pages.Add(report2.Pages[i]);
        }
    }

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

    // Show the Print Preview form.
    report1.ShowPreviewDialog();
}
Visual BasicCopyCode image复制代码
Private Sub MergeTwoReports()
    ' Create the 1st report and generate its document.
    Dim report1 As XtraReport1 = New XtraReport1()
    report1.CreateDocument()

    ' Create the 2nd report and generate its document.
    Dim report2 As XtraReport2 = New XtraReport2()
    report2.CreateDocument()

    ' Merge pages of two reports, page-by-page.
    Dim minPageCount As Integer = Math.Min(report1.Pages.Count, report2.Pages.Count)
    Dim i As Integer = 0
    Do While i < minPageCount
        report1.Pages.Insert(i * 2 + 1, report2.Pages(i))
        i += 1
    Loop

    If report2.Pages.Count <> minPageCount Then
        i = minPageCount
        Do While i < report2.Pages.Count
            report1.Pages.Add(report2.Pages(i))
            i += 1
        Loop
    End If

    ' Reset all page numbers in the resulting document.
    report1.PrintingSystem.ContinuousPageNumbering = True

    ' Show the Print Preview form.
    report1.ShowPreviewDialog()
End Sub

下面的代码演示了如何重新排列报表页的顺序,以便于可以被打印为一个手册 (第一页、最后一页、第二页、倒数第二页、第三页等)。

C#CopyCode image复制代码
private void CreateBooklet() {
    // Create the 1st report and generate its document.
    XtraReport1 report1 = new XtraReport1();
    report1.CreateDocument();

    // Preserve original page numbers on all pages.
    report1.PrintingSystem.ContinuousPageNumbering = false;

    // Create a booklet.
    int centerPageIndex = Convert.ToInt32((report1.Pages.Count - 1) / 2);
    for (int i = 0; i < centerPageIndex; i++) {
        report1.Pages.Insert(i * 2 + 1, report1.Pages[report1.Pages.Count - 1]);
    }

    // Show the Print Preview form.
    report1.ShowPreviewDialog();
}
Visual BasicCopyCode image复制代码
Private Sub CreateBooklet()
    ' Create the 1st report and generate its document.
    Dim report1 As XtraReport1 = New XtraReport1()
    report1.CreateDocument()

    ' Preserve original page numbers on all pages.
    report1.PrintingSystem.ContinuousPageNumbering = False

    ' Create a booklet.
    Dim centerPageIndex As Integer = Convert.ToInt32((report1.Pages.Count - 1) / 2)
    Dim i As Integer = 0
    Do While i < centerPageIndex
        report1.Pages.Insert(i * 2 + 1, report1.Pages(report1.Pages.Count - 1))
        i += 1
    Loop

    ' Show the Print Preview form.
    report1.ShowPreviewDialog()
End Sub

CodeCentralShow Me

在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E159。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。

Expand image参阅