ActiveReports10 中实现报表拼接

发布时间:2016/06/30 00:06 发布者:lenka.guo

返回博客中心

有了ActiveReports 就可以将多个独立报表拼成一个整个大的报表,报表拼接的方法主要取决于报表类型。

接下来,让我们了解下,不同类型的报表如何进行拼接。

区域报表

区域 报表由于它的组织结构的特殊性,有以下方法来实现拼接:

1. 添加或插入报表页

2. 覆盖报表页

3.将报表保存成文档之后拼接报表

 

添加或插入报表页

在区域报表中,Document.Pages 属性(PageCollection 类)保存了报表生成的每一页。您可以执行添加,插入,赋值或删除报表页等操作,使用PagesCollection类提供的“Add”,”AddRange”,”CopyTo”,”Insert”,”InsertRange”,”Remove”等。

 

image

 

 

//C#
// Run each report.
rpt1.Run(false);
rpt2.Run(false);
// Add the pages of rpt2 after rpt1.
for (int i = 0; i < rpt2.Document.Pages.Count; i++)
{
  rpt1.Document.Pages.Add(rpt2.Document.Pages[i].Clone());
}

 

一旦拼接成功,可以在报表Viewer中显示报表了,设置打印布局可以指定打印设置,打印报表也可以选择逆向打印。

注意:区域报表只能与区域报表连接。

拼接报表页面

区域报表,可以使用Page的Overlay方法,将其他报表拼接到首个报表后面。

image

//C#
// Run each report.
rpt1.Run(false);
rpt2.Run(false);
// Overlay the first page of rpt2 onto each page of rpt1.
for (int i = 0; i < rpt1.Document.Pages.Count; i++)
{
  rpt1.Document.Pages[i].Overlay(
    (GrapeCity.ActiveReports.Document.Section.Page)
      rpt2.Document.Pages[0].Clone());
}

 

一旦连接,就可以在报表Viewer中展示报表,导出并打印。

保存成Document对象时连接页面

 

// C#
        // Specify paths to reports that were saved to RDF format.
        string invoiceRdf = null;
        invoiceRdf = Application.StartupPath.ToString() + “..\\..\\..\\Invoice.rdf”;
        string letterRdf = null;
        letterRdf = Application.StartupPath.ToString() + “..\\..\\..\\Letter.rdf”;
        // Create a section report object to hold the pages of the final merged report.
        GrapeCity.ActiveReports.SectionReport merge = new GrapeCity.ActiveReports.SectionReport();
        // Create a section report document object in which to load pages from the RDFs.
        GrapeCity.ActiveReports.Document.SectionDocument fRdf = new GrapeCity.ActiveReports.Document.SectionDocument();
        // Load the invoice report into the document object.
        fRdf.Load(invoiceRdf);
        // Add the pages of the invoice report to the merge report.
        merge.Document.Pages.AddRange(fRdf.Pages);
        // Clear the pages from the document object.
        fRdf.Pages.Clear();
        // Load the letter report into the document object.
        fRdf.Load(letterRdf);
        // After each invoice page, insert a letter page.
        for (int i = 0; i < = fRdf.Pages.Count – 1; i++)
        {
            merge.Document.Pages.Insert(i + 1, fRdf.Pages[i]);
            i = i + 1;
        }

 

页面和RDL 报表

页面和RDL 报表未提供报表连接的方法,但是有两种方法可用:

  • 将报表导出为PDF 文件后,拼接。
  • 使用多页报表布局(仅限页面报表)

合并PDF文件

使用PDF 渲染API将报表导出为PDF 文件,导出成功后将多个PDF 文件内容拼接。

// C#
    // Create a new page report.
    PageReport _reportDef = new PageReport(new FileInfo(@”..\..\NWindTable.rdlx”));
    PageDocument reportDocument = new PageDocument(_reportDef);
 
    // Set up the PDF file names and paths.  
    string exportFileBefore = Application.StartupPath + @”/../../one.pdf”;
    string exportFileAfter = Application.StartupPath + @”/../../three.pdf”;
    string exportFileRdlx = “merge.pagereports.pdf”;
 
    // Set up PDF files to merge into the export.
    settings = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
    settings.DocumentToAddBeforeReport = exportFileBefore; 
    settings.DocumentToAddAfterReport = exportFileAfter; 
 
    FileInfo myFile1 = new FileInfo(exportFileRdlx);
 
    // Export the report to PDF and merge the other PDF files into it.  
    PdfRenderingExtension pdfRenderingExtension = new PdfRenderingExtension();
    FileStreamProvider _outputProvider = new FileStreamProvider(myFile1.Directory, myFile1.Name);
    reportDocument.Render(pdfRenderingExtension, _outputProvider, settings);

 

使用多页布局

与连接报表不同,页面报表中使用不同数据控件来输出报表数据,当数据量过多时,可以自行换页展示。手动添加页就可以实现多页拼接。

image

 

您在使用产品过程中有任何疑问,可以登录葡萄城开发者社区和经验丰富的技术工程师、ActiveReports开发人员交流:了解更多

了解ActiveReports产品更多特性:

/developer/activereports

下载产品体验产品功能:

/download/?pid=16


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网