锐浪报表 Grid++Report 子报表 Delphi

    锐浪报表 Grid++Report 是国内较好的报表控件,本人一直使用它,做出很多特色的报表。可以说你的报表设计出来,它基本上能做出来。

    但是它帮助文件上,说的不深,近期因为要做一个有关社工的报表,大表中,嵌套2个子表。可以说,一个表到三个数据集,分别打印。

    在认真看了帮助的基础上,网上探索,基本无此类,特别是Delphi的帮助,几乎为零。经二天摸索,做出来了。

    一、设计思路

    1、大表和二个小表,可以设计为三个表,分别使用三个GridppReport控件,取名GridppReport1,GridppReport_sub1,GridppReport_sub2。

    2、设计报表打印模板

   (1)常规设计大表的模板

   (2)在需要小表的地方,使用ReportHeader或ReportFooter作为容器,通过插入“子报表“,默认名称SubReport1,实际上它是IGridppReport对象。

   (3)在报表模板编辑内,通过双击SubReport1,打开子报表进行编辑。

    注意:对于子报表,有二种编辑方式,一是上面讲的,通过 双击SubReport1,打开子报表进行编辑。二是另外设计一个报表模板,作为子报表模板,在SubReport1的“报表模板文件”属性中加入,即可。二种方式效果一样。

    3、三个数据集的导入

     数据的导入,主要有多种方式:

  (1)通过ADOQuery导入

  (2)通过XML或JSON导入

  (3)通过ClientDataset内在表中的现有数据,这种就是人们具有编程主导权的数据导入方式,最适合各种上表格的设计使用。

    因为,ClientDataset,已经在客户端的内存中,对于三层数据或云端数据来说,就近,最快速,最准确地打印,效果好,经测试在  B/S 程序中,打印也就很好的,可以通过  Grid++Report的插件方式打印,效果很好。

    本人最爱用此方式。这是,打印即时报表的最佳方式,如打印收据、发票等等。

    问题来了,这种方式,要通过  DetailGrid.Recordset 的Append方法加入一行数据,它需要在FetchRecord事件中执行。
       4、关联子报表对象

     子报表的对象是IGridppReport对象,实例的对象是TGridppRepor,二者是从属关系 ,找到他们的关系,可以关联的部位,很重要。

var SubReport1,SubReport2:IGridppReport;
begin
//关联子报表部件框的报表对象
  SubReport1:=GridppReport1.ControlByName('SubReport1').AsSubReport.Report;
  SubReport2:=GridppReport1.ControlByName('SubReport2').AsSubReport.Report;

     下一步最重要,就是让实例,即GridppReport_sub1与SubReport1关联:

//子报表部件框的报表对象关联一个外部报表对象,以便响应报表事件
   GridppReport1.ControlByName('SubReport1').AsSubReport.Report := GridppReport_Sub1.DefaultInterface;

    这样,我们就可以通过对GridppReport_Sub1的相关事件中,对子报表进行报表进行初始化和数据对接打印了。

   二、相关代码

    1、主报表

procedure TGroup_2_Frm.GridppReport1Initialize(Sender: TObject);
var H1,H2,N:Double;
    i:integer;
begin
  GridppReport1.LoadFromFile( ReportPath+'社工_小组_工作计划.grf' );
  H1:=StrToFloat(Edit1.text);
  H2:=StrToFloat(Edit2.text);
  GridppReport1.DesignTopMargin:=H1;
  GridppReport1.DesignBottomMargin:=H2;

  GP[0]:=GridppReport1.AddParameter('A1',grptString);
  GridppReport1.ParameterByName('A1').AsString:=DBEdit4.Text;
  GP[1]:=GridppReport1.AddParameter('A2',grptString);
  GridppReport1.ParameterByName('A2').AsString:=DBEdit5.Text;
  GP[2]:=GridppReport1.AddParameter('A3',grptString);
  GridppReport1.ParameterByName('A3').AsString:=DBEdit6.Text;
  GP[4]:=GridppReport1.AddParameter('A4',grptString);
  GridppReport1.ParameterByName('A4').AsString:=DBEdit8.Text;
  GP[5]:=GridppReport1.AddParameter('A5',grptString);
  GridppReport1.ParameterByName('A5').AsString:=DBEdit1.Text+DBEdit2.Text;
  GP[6]:=GridppReport1.AddParameter('A6',grptString);
  GridppReport1.ParameterByName('A6').AsString:=DBEdit3.Text;
  GP[7]:=GridppReport1.AddParameter('A7',grptString);
  GridppReport1.ParameterByName('A7').AsString:=DBEdit7.Text;
  GP[8]:=GridppReport1.AddParameter('A8',grptString);
  GridppReport1.ParameterByName('A8').AsString:=DBEdit9.Text;
  GP[9]:=GridppReport1.AddParameter('A9',grptString);
  GridppReport1.ParameterByName('A9').AsString:=DBMemo1.Text;

  GP[10]:=GridppReport1.AddParameter('A10',grptString);
  GridppReport1.ParameterByName('A10').AsString:=DBRichedit1.Text;
  GP[11]:=GridppReport1.AddParameter('A11',grptString);
  GridppReport1.ParameterByName('A11').AsString:=DBRichedit2.Text;
  GP[12]:=GridppReport1.AddParameter('A12',grptString);
  GridppReport1.ParameterByName('A12').AsString:=DBRichedit3.Text;
  GP[13]:=GridppReport1.AddParameter('A13',grptString);
  GridppReport1.ParameterByName('A13').AsString:=DBRichedit4.Text;
  GP[14]:=GridppReport1.AddParameter('A14',grptString);
  GridppReport1.ParameterByName('A14').AsString:=DBRichedit5.Text;
  GP[15]:=GridppReport1.AddParameter('A15',grptString);
  GridppReport1.ParameterByName('A15').AsString:=DBRichedit6.Text;

  GP[16]:=GridppReport1.AddParameter('A16',grptString);
  GridppReport1.ParameterByName('A16').AsString:=DBRichedit7.Text;
  GP[17]:=GridppReport1.AddParameter('A17',grptString);
  GridppReport1.ParameterByName('A17').AsString:=DBRichedit8.Text;
  GP[18]:=GridppReport1.AddParameter('A18',grptString);
  GridppReport1.ParameterByName('A18').AsString:=DBRichedit9.Text;
  with ClientDataset4 do
  begin
    N:=0;
    while Not Eof do
    begin
      N:=N+FieldByName('金额').AsCurrency;
      Next;
    end
  end;
  GP[19]:=GridppReport1.AddParameter('A19',grptString);
  GridppReport1.ParameterByName('A19').AsString:='申请经费总计: '+FloattoStr(N)+'(元)';
end;

procedure TGroup_2_Frm.GridppReport1FetchRecord(Sender: TObject);
var SubReport1,SubReport2:IGridppReport;
begin
//关联子报表部件框的报表对象
  SubReport1:=GridppReport1.ControlByName('SubReport1').AsSubReport.Report;
  SubReport2:=GridppReport1.ControlByName('SubReport2').AsSubReport.Report;

//子报表部件框的报表对象关联一个外部报表对象,以便响应报表事件
   GridppReport1.ControlByName('SubReport1').AsSubReport.Report := GridppReport_Sub1.DefaultInterface;
   GridppReport1.ControlByName('SubReport2').AsSubReport.Report := GridppReport_Sub2.DefaultInterface;

end;

    2、GridppReport_Sub1

procedure TGroup_2_Frm.GridppReport_Sub1Initialize(Sender: TObject);
begin
  GridppReport_Sub1.LoadFromFile(ReportPath+'社工_小组_1.grf');
  GR[0]:=GridppReport_Sub1.FieldByName('单元');
  GR[1]:=GridppReport_Sub1.FieldByName('单元名称');
  GR[2]:=GridppReport_Sub1.FieldByName('单元目标');
  GR[3]:=GridppReport_Sub1.FieldByName('内容方式');
  GR[4]:=GridppReport_Sub1.FieldByName('时间配置');
  GR[5]:=GridppReport_Sub1.FieldByName('工作人员');
end;


procedure TGroup_2_Frm.GridppReport_Sub1FetchRecord(Sender: TObject);
begin
  if not ClientDataSet3.Active then Exit;
  with ClientDataSet3 do
  Begin
    First;
    While Not Eof do
    begin
      GridppReport_Sub1.DetailGrid.Recordset.Append;
      GR[0].Value:=FieldByName('单元').AsString;
      GR[1].Value:=FieldByName('名称').AsString;
      GR[2].Value:=FieldByName('目标').AsString;
      GR[3].Value:=FieldByName('内容方式').AsString;
      GR[4].Value:=FieldByName('时长').AsString;
      GR[5].Value:=FieldByName('工作人员').AsString;
      GridppReport_Sub1.DetailGrid.Recordset.Post;
      Next;
    end;
    First;
  end;
end;

    3、GridppReport_Sub1

procedure TGroup_2_Frm.GridppReport_Sub2Initialize(Sender: TObject);
begin
  GridppReport_Sub1.LoadFromFile(ReportPath+'社工_小组_2.grf');
  GR[0]:=GridppReport_Sub2.FieldByName('序号');
  GR[1]:=GridppReport_Sub2.FieldByName('项目');
  GR[2]:=GridppReport_Sub2.FieldByName('单价');
  GR[3]:=GridppReport_Sub2.FieldByName('数量');
  GR[4]:=GridppReport_Sub2.FieldByName('金额');
  GR[5]:=GridppReport_Sub2.FieldByName('来源');
end;

procedure TGroup_2_Frm.GridppReport_Sub2FetchRecord(Sender: TObject);
begin
  if not ClientDataSet4.Active then Exit;
  with ClientDataSet4 do
  Begin
    First;
    While Not Eof do
    begin
      GridppReport_Sub2.DetailGrid.Recordset.Append;
      GR[0].Value:=FieldByName('单元').AsString;
      GR[1].Value:=FieldByName('项目').AsString;
      GR[2].Value:=FieldByName('单价').AsString;
      GR[3].Value:=FieldByName('数量').AsString;
      GR[4].Value:=FieldByName('金额').AsString;
      GR[5].Value:=FieldByName('经费来源').AsString;
      GridppReport_Sub2.DetailGrid.Recordset.Post;
      Next;
    end;
    First;
  end;
end;

    三、打印效果

   上图窗口,下图打印效果,数据随意填写。

 

     上述观点,仅为个人笔记。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
锐浪Grid Report报表Web版是一个基于Java的报表生成工具,它可以帮助用户方便地创建和展示数据报表。以下是它的使用手册。 1. 环境准备 在使用锐浪Grid Report报表之前,确保您已经安装好Java开发环境,并且已经配置好相关的数据库。 2. 下载和安装 您可以从官方网站上下载锐浪Grid Report报表的Web版安装包。下载完成后,将其解压并将相关文件拷贝至您的Web应用程序的目录中。 3. 创建报表模板 使用锐浪Grid Report报表,首先您需要创建一个报表模板。您可以使用工具提供的可视化编辑器来设计您的报表模板。在这个编辑器中,您可以添加数据源、设置样式和布局、定义数据关联等。 4. 配置数据源 在报表模板中,您需要配置数据源以获取报表数据。锐浪Grid Report支持多种数据源类型,如数据库、Excel、CSV等。您需要填写相应的连接信息,例如数据库的连接字符串、用户名和密码等。 5. 设置参数和过滤器 如果您需要设置报表的参数和过滤器,可以在报表模板中定义它们。参数和过滤器可以帮助您动态地过滤数据,使报表更加灵活和可定制。 6. 生成和预览报表 当您完成了报表模板的设计和配置后,可以通过点击生成按钮生成报表。然后,您可以预览生成的报表,以确保它符合您的要求。 7. 导出和打印报表 锐浪Grid Report报表支持多种导出格式,如PDF、Excel、HTML等。您可以选择将报表导出为您需要的格式,并随时进行打印或分享。 总结: 锐浪Grid Report报表Web版是一个强大且易于使用的报表生成工具,它提供了可视化的编辑器来设计和配置报表模板,支持灵活的数据源配置和参数设置,以及多种导出和打印选项。通过对这些功能的灵活运用,您可以轻松地创建出符合您需求的高质量报表

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值