TcxSpreadSheetBook 类似Excel表格控件的使用方法

 TcxSpreadSheetBook 是一个类似Excel的控件,可以实现类型Excel的导入导出、合并单元格、设置单元格的格式等等功能

下面列举一些控件的主要功能以及实现方法
1:合并单元格
procedure SetMergedStateA(Left, Top, Right,
  Bottom: Integer; IsMerge: Boolean);
var
  ARect: TRect;  
begin  
  with CX_StatResult.ActiveSheet do
  begin
    ARect.Left:=Left;
    ARect.Top:=Top;
    ARect.Right:=Right;
    ARect.Bottom:=Bottom;
    SetMergedState(ARect, True);
  end;
end;
 
使用例如:SetMergedStateA(0,0,4,0,True);
Left0,Right0是第一行
Right4,Buttom0,是第四列
也就是第一行 0-4列被合并
 
2:设置单元格格式
procedure SetCellsStyle(AValuesSet: TStyleValueSet;
  AAlign: TcxHorzTextAlign; AFontSize: Integer; const AFontName: string;
  AStyles: TFontStyles);
 procedure SetValue(AFlag: TStyleValue; ANeedStyle. TFontStyle;
    var ASetStyles: TFontStyles);
  begin
    if AFlag in AValuesSet then
    begin
      if ANeedStyle. in AStyles then
        Include(ASetStyles, ANeedStyle)
      else
        Exclude(ASetStyles, ANeedStyle);
    end;
  end;
 
var
  I, J: Integer;
  AStyle. TFontStyles;
 
begin
  with CX_StatResult do
  try
    BeginUpdate;
    with ActiveSheet do
    begin
      for I := SelectionRect.Left to SelectionRect.Right do
        for J := SelectionRect.Top to SelectionRect.Bottom do
        with GetCellObject(I, J) do
        try
          with Style. do
          begin
            AStyle.:= Font.Style;
            if svFontName in AValuesSet then
              Font.Name := AFontName;
            if svSize in AValuesSet then
              Font.Size := AFontSize;
            if svAlign in AValuesSet then
              HorzTextAlign := AAlign;
            SetValue(svBold, fsBold, AStyle);
            SetValue(svItalic, fsItalic, AStyle);
            SetValue(svUnderline, fsUnderline, AStyle);
            SetValue(svStrikeOut, fsStrikeOut, AStyle);
            Font.Style.:= AStyle;
          end;
        finally
          Free;
        end;
    end;
  finally
    EndUpdate;
    UpdateControl;
  end;
end;
 
用到的枚举类型
  TStyleValue = (svAlign, svFontName, svSize, svBold, svItalic, svUnderline, svStrikeOut);
  TStyleValueSet = set of TStyleValue;
 
使用例子:
SetCellsStyle([svBold,svAlign], haCenter, 0, '宋体', [fsBold]);
位置居中、字体是宋体、字体黑体
 
3:修改某一个单元格文字
  Cell := CX_StatResult.Pages[0].GetCellObject(CurrentCol, CurrentRow);
  Cell.Text:='合计';
 
  CurrentCol, CurrentRow 是当前列,当前行
 
4:选定某一个单元格
  CX_StatResult.Pages[0].SelectCell(CurrentCol,CurrentRow,False);
 
 
 
注意:我们在修改某一个单元格格式的时候,先选择一个单元格,再进行修改
 
本文地址:http://www.xszlo.com/article/2012-11-27/7520.html,转发请保留这个地址,谢谢

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28623727/viewspace-757831/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28623727/viewspace-757831/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值