zoukankan      html  css  js  c++  java
  • 如何合并多个报表

    在本文中,我将向你展示如何使用应用程序的代码,将两个或者更多的报表合并到一个报表中。当你想根据类别合并类似的报表时,这可能很有用。

    要将报表附加到上一个,请使用报表对象的Prepare方法。必须提供TRUE值作为该方法的参数。我们看看下面这个例子。

    创建一个WinForms应用程序。在项目中添加对FastReport.dll库的引用。

    接下来,在表单中添加三个按钮:报表1、报表2、组合报表。然后双击第一个按钮。

    现在我们使用FastReport库:

    using FastReport;

    设置报表路径:

    string report_path = @"K:MyDocuments";

    现在添加第一个按钮的代码:

    private void button1_Click(object sender, EventArgs e)
     {
     Report report1 = new Report();
     Report1.Load(report_path + "report1.frx");
     Report1.Prepare();
     Report1.ShowPrepared();
     }
    

    在这里,我们创建了一个报表对象的实例,加载报表,准备报表并显示。报表模板如下所示:

    如何合并多个报表

    双击第二个按钮:

    private void button2_Click(object sender, EventArgs e)
     {
     Report report2 = new Report();
     Report2.Load(report_path+"report2.frx");
     Report2.Prepare();
     Report2.ShowPrepared();
     }
    

    接下来的流程和第一个按钮一样。报表模板也是类似的:

    如何合并多个报表

    我们添加第三个按钮的代码:

    private void button3_Click(object sender, EventArgs e)
     {
     Report report1 = new Report();
     report1.Load(report_path + "report1.frx");
     report1.Prepare();
     report1.Load(report_path + "report2.frx");
     report1.Prepare(true);
     report1.ShowPrepared();
     }
    

    如你所见,我们创建了报表对象“report1”。接下来,我们加载第一份报表并做好准备。然后加载第二份报表。在最后一行代码中,我们显示了报表对象。注意行report1.Prepare(true)。我们将true的值传递给函数参数。这意味着当前的报表将附在前一份报表上。而且,只要你喜欢,你可以合并任意数量的报表。

    现在启动我们的应用程序:

    如何合并多个报表

    如果我们点击Report 1按钮,我们会获得第一个报表:

    如何合并多个报表

    按下按钮Report 2.我们得到第二个报表:

    如何合并多个报表

    最后,我们按下第三个按钮:

    如何合并多个报表

    在这种情况下,我们得到了一份有两页的报表。第一页显示第一个报表,第二显示第二个。就是这样,将两个报表合并为一个报表不会有任何困难,并且不会创建额外的报表对象。 

  • 相关阅读:
    HDU 1269 迷宫城堡
    HDU 4771 Stealing Harry Potter's Precious
    HDU 4772 Zhuge Liang's Password
    HDU 1690 Bus System
    HDU 2112 HDU Today
    HDU 1385 Minimum Transport Cost
    HDU 1596 find the safest road
    HDU 2680 Choose the best route
    HDU 2066 一个人的旅行
    AssetBundle管理机制(下)
  • 原文地址:https://www.cnblogs.com/zhaogaojian/p/8349762.html
Copyright © 2011-2022 走看看