利用cxSpreadSheetBook电子表格控件完成复杂性的报表例子

如果报表复杂,可以利用cxSpreadSheetBook电子表格控件来生成报表。

下面例子是装载数据同时设置电子表格格式:

procedure TAO_RepShowData.LoadRepData;
var
  CurCursor: TCursor;
begin
  CurCursor := Screen.Cursor;                              // 光标设置
  Screen.Cursor := crHourGlass;
  try
    cxSpreadBook.BeginUpdate;
    LoadTitle;                                                      //从数据库取数加载表格标题                       
    LoadData;                                                     //从数据库取数加载表格数据
    cxSpreadBook.ActiveSheet.SelectCell(-1, -1, False);//光标位置在表格外
  Finally
    cxSpreadBook.EndUpdate;
    cxSpreadBook.Recalc;                                   //重新计算表格
    cxSpreadBook.ActivePage := 0;                          // 第一页 

    Screen.Cursor := CurCursor;                     // 光标设置 

  end;
end;

procedure TAO_RepShowData.LoadTitle;   //装载表格标题
var
  i, CRow: integer;
  CHeader: TcxSSHeader;
begin
  i := cdsAnalyseField.RecordCount;  //合并单元格格数

  //GlobalVars.Values['REPNAME'] 是个变量
  SetCellText(1, 0, GlobalVars.Values['REPNAME']);  //设置表格头名称(报表名称)    cxSpreadBook.ActiveSheet.Caption := GlobalVars.Values['REPNAME'];//页标签名称
  cxSpreadBook.ActiveSheet.SelectCell(1, 0); //选中单元格
  SetMergedStateA(1, 0, i + 1, 0, true);  //合并单元格
  SetCellFont(1, 0, i, 0, [fsBold], 20);  //设置字体大小
  //SetCellsStyle([svAlign], haCenter, 0, cbxFont.Text, []);
  SetCellAlignment(1, 0, i + 1, 0, haCenter, vaCenter);//格式居中
  SetCellText(1, 1, GlobalVars.Values['JHDW']);  //设置金额单位
  SetCellText(1, 2, '单位名称');//设置表格表题
  SetCellAlignment(1, 2, 1, 2, haCenter, vaCenter);//格式居中

  SetCellFont(1, 2, 1, 2, [fsBold], 8);
  CHeader := cxSpreadBook.ActiveSheet.Cols;
  CHeader.Size[1] := 180;//列宽度
  cdsRepDwData.DisableControls;
  try
    CRow := 3;//从第三行开始
    cxSpreadBook.ActivePage := 0;
    cdsRepDwData.First;
    while not cdsRepDwData.eof do begin
      SetCellText(1, CRow, cdsRepDwDataDANWEI_MINGCHANG.Value);//从数据库中取数填入表格单元
      cdsRepDwData.Next;
      Inc(CRow);
    end;
    SetmnuCellBorders(1, 2, 1, CRow - 1, 5);//设置表格格式
    //SetCellPattern(1,2,1,CurRow-1,23,1,fsSolid);
  Finally
    cdsRepDwData.EnableControls;                         // restore original cursor
  end;
end;

procedure TAO_RepShowData.LoadData;//装载数据
var
  CurCol, CurRow: Integer;
  CHeader: TcxSSHeader;
begin
  if cdsAnalyseField.RecordCount > 0 then
  begin
    try

      cxSpreadBook.ActivePage := 0;
      cdsAnalyseField.DisableControls;
      CurCol := 2;//从第二列开始
      CurRow := 3;//从第三行开始
      cdsAnalyseField.First;
      while not cdsAnalyseField.eof do begin
        CHeader := cxSpreadBook.ActiveSheet.Cols;
        CHeader.Size[CurCol] := 120;//列宽度
        SetCellText(CurCol, 2, cdsAnalyseFieldANALYSE_FIELD_NAME.Value);
        try
          OpenRepDwData(GlobalVars.Values['DANWEI_QYDM'], StrToInt(GlobalVars.Values['REP_VOL_KEY']), cdsAnalyseFieldSIGN_CELL_KEY.Value);
          cdsRepDwData.DisableControls;
          CurRow := 3;
          cdsRepDwData.First;
          while not cdsRepDwData.eof do begin
            if cxSpreadBook.ActiveSheet.GetCellObject(1, CurRow).Text = cdsRepDwDataDANWEI_MINGCHANG.Value then
            begin
              if cdsRepDwDataSIGN_DELL_TYPE.Value = 0 then  //RoundFloat(StrToFloat(Text),2)
                if cdsRepDwDataREP_DATA.Value = 0 then
                  SetCellText(CurCol, CurRow, '0')
                else
                begin
                  if GlobalVars.Values['JHDW'] = '金额单位:元' then//加载数据,金额换算成元。
                    SetCellText(CurCol, CurRow, FormatFloat('#,#.00', cdsRepDwDataREP_DATA.Value));    //FormatFloat('#,#.##',cdsRepCellDataREP_DATA.Value))
                  if GlobalVars.Values['JHDW'] = '金额单位:万元' then//加载数据,金额换算成万元。
                    SetCellText(CurCol, CurRow, FormatFloat('#,#.00', StrToFloat(FloatToStr(cdsRepDwDataREP_DATA.Value / 10000))));
                  if GlobalVars.Values['JHDW'] = '金额单位:亿元' then//加载数据,金额换算成亿元。
                    SetCellText(CurCol, CurRow, FormatFloat('#,#.00', StrToFloat(FloatToStr(cdsRepDwDataREP_DATA.Value / 100000000))));
                end;
              if cdsRepDwDataSIGN_DELL_TYPE.Value = 1 then
                SetCellText(CurCol, CurRow, cdsRepDwDataREP_TEXT.Value);
            end;
            cdsRepDwData.Next;
            Inc(CurRow);
          end;
        Finally
          cdsRepDwData.EnableControls;                         // restore original cursor
        end;
        cdsAnalyseField.Next;
        Inc(CurCol);
      end;
      SetCellFormat(2, 3, CurCol, CurRow, 4);//设置表格格式
      SetmnuCellBorders(2, 2, CurCol - 1, CurRow - 1, 5);//设置表格线
      SetCellAlignment(2, 2, CurCol, 2, haCenter, vaCenter);
      SetCellFont(2, 2, CurCol, 2, [fsBold], 8);
    Finally
      cdsAnalyseField.EnableControls;                         // restore original cursor
    end;
  end;
end;

转载于:https://www.cnblogs.com/hsbs/p/4677254.html

数据库报表设计系统(以下简称为报表系统),是专用于对访问远程数据库服务器所得的数据,如:SQL Server2000、Oracle等进行报表设计、预览和打印的系统。它设计自由、样式多样、操作简单,和通常的字处理排版类似。 报表系统主要包括系统菜单、工具栏、设计区和预览区四大部分。其中系统菜单中的主要功能都能在工具栏中实现,工具栏以包括系统工具、表头元件、数据元件、排版工具、位置调整工具,具体功能如下: 1)系统工具:主要有新建报表、打开报表、保存报表、打印设置、打印预览、剪切、复制、粘帖等; 2)表头元件:主要有标签、文本标签(用于多行标签)、系统数据(用于显示打印日期、页码、页数等)、图象、直线、矩形(用于制作表格)和条形码等工具。 3)数据元件:主要有数据标签(用于显示数据字段值)、数据文本(用于显示TXT数据)、数据RTF(用于显示RTF数据)、求和(用于对字段求和)、图象(用于显示图象字段)、数据条形码、区域框(用于制作表格)以及数据字段框(用于选择要显示的数据字段名称)。 4)排版工具:主要有对文字进行加粗、斜体、下画线、居左、居中、居右,改变字体及大小、颜色,置前、置后工具用于对重合的元件进行调整。 5)位置调整工具:主要有上下左右移动元件,对元件上下左右对齐(同时选择多个元件就可使用此工具选择对齐方式)和改变元件大小工具,即选择两个以上的元件,使用此工具对基于参照元件进行放大和缩小其它元件。 设计区主要用于报表版面设计,包括表头(用于设计报表标题)、内容(用于设计报表表格)、页脚(用于设计报表落款);预览区主要用于报表预览,即可进行实时预览,也就是在设计区中修改了报表,立刻就可以在预览区显示效果,预览区上还有打印按钮、预览比例按钮和翻页按钮等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值