ITPub博客

首页 > Linux操作系统 > Linux操作系统 > TcxSpreadSheetBook 类似Excel表格控件的使用方法

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

原创 Linux操作系统 作者:sbzldlb 时间:2013-04-06 15:47:07 0 删除 编辑

 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博客 ” ,链接:https://blog.itpub.net/28623727/viewspace-757831/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-04-04

  • 博文量
    28
  • 访问量
    95539