cxSpreadSheetBook控件使用

      因为项目需要读取excel的数据,并且可以进行编辑、而且需要进行界面样式的调整,所以进行这个控件的研究。
cxSpreadSheetBook是一个Excel控件,可以读取Excel的数据,并且可以进行控件的单元格进行控制,可以实现合并单元格、设置单元格宽度、设置单元格的字体大小、字体样式、设置单元格文字是否居中等等。下面是技巧

1:首先定义单元格样式

  1.   TStyleValue = (svAlign, svFontName, svSize, svBold, svItalic, svUnderline, svStrikeOut);
  2.   TStyleValueSet = set of TStyleValue;

文字的位置、文字的字体名、大小、是否黑体、是否下划线等等

2:合并单元格

  1. procedure SetMergedStateA(Left, Top, Right,
  2.   Bottom: Integer; IsMerge: Boolean);
  3. var
  4.   ARect: TRect;  
  5. begin  
  6.   with CX_StatResult.ActiveSheet do
  7.   begin
  8.     ARect.Left:=Left;
  9.     ARect.Top:=Top;
  10.     ARect.Right:=Right;
  11.     ARect.Bottom:=Bottom;
  12.     SetMergedState(ARect, True);
  13.   end;
  14. end;
  15.  

使用方法:SetMergedStateA(0,0,15,0,True);

3:设置单元格文字的样式

  1. procedure TfrmStatiWenShu.SetCellsStyle(AValuesSet: TStyleValueSet;
  2.   AAlign: TcxHorzTextAlign; AFontSize: Integer; const AFontName: string;
  3.   AStyles: TFontStyles);
  4.   procedure SetValue(AFlag: TStyleValue; ANeedStyle: TFontStyle;
  5.     var ASetStyles: TFontStyles);
  6.   begin
  7.     if AFlag in AValuesSet then
  8.     begin
  9.       if ANeedStyle in AStyles then
  10.         Include(ASetStyles, ANeedStyle)
  11.       else
  12.         Exclude(ASetStyles, ANeedStyle);
  13.     end;
  14.   end;
  15.  
  16. var
  17.   I, J: Integer;
  18.   AStyle: TFontStyles;
  19.  
  20. begin
  21.   with CX_StatResult do
  22.   try
  23.     BeginUpdate;
  24.     with ActiveSheet do
  25.     begin
  26.       for I := SelectionRect.Left to SelectionRect.Right do
  27.         for J := SelectionRect.Top to SelectionRect.Bottom do
  28.         with GetCellObject(I, J) do
  29.         try
  30.           with Style do
  31.           begin
  32.             AStyle := Font.Style;
  33.             if svFontName in AValuesSet then
  34.               Font.Name := AFontName;
  35.             if svSize in AValuesSet then
  36.               Font.Size := AFontSize;
  37.             if svAlign in AValuesSet then
  38.               HorzTextAlign := AAlign;
  39.             SetValue(svBold, fsBold, AStyle);
  40.             SetValue(svItalic, fsItalic, AStyle);
  41.             SetValue(svUnderline, fsUnderline, AStyle);
  42.             SetValue(svStrikeOut, fsStrikeOut, AStyle);
  43.             Font.Style := AStyle;
  44.           end;
  45.         finally
  46.           Free;
  47.         end;
  48.     end;
  49.   finally
  50.     EndUpdate;
  51.     UpdateControl;
  52.   end;
  53. end;

如下使用:

  1. CX_StatResult.Pages[0].SelectCell(0,0,False);
  2.   SetCellsStyle([svBold,svAlign], haCenter, 0, '', [fsBold]);

首先选择单元格,然后调用SetCellsStyle设置单元格格式

3:控件一个表格也不选择,使用如下语句:

  1. CX_StatResult.Pages[0].SelectCell(-1,-1,False);  


4:设置某一个列的宽度

  1. CX_StatResult.Pages[0].Cols.Size[15]:=70;


5:设置某个单元格的文字

  1. Cell := CX_StatResult.Pages[0].GetCellObject(15, 1);
  2.   Cell.Text:='备注';


6:导入Excel

  1. CX_StatResult.LoadFromFile();

 

 

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一套Developer Express件包 For Delphi7Developer Express件简介Express Scheduler Suite可以建立类似于Outlook中日历那样的空间,计划任务。ExpressQuantumGrid Suite一个超级牛的Grid件,不要告诉我不知道什么是Grid,其中Filter功能也是非常厉害的。ExpressBars Suite非常厉害非常厉害的工具条菜单件。ExpressPrinting System 打印件,可以和ExpressQuantumGrid 完美连接,还没发现有没有报表功能,要不就是没有报表功能,完美的ExpressQuantumGrid件就可以代替了。ExpressQuantumTreeList Suite 非常牛的树状件,跟ExpressQuantumGrid 结合起来很厉害的。ExpressNavBar 是用来做类似于XP下的浏览器左边的导航条的,非常地帅。ExpressLayout Control 好像是界面布局的件。ExpressDBTree Suite非常好用的数据库树形列表件。ExpressMasterView专门用作总单细单甚至多层的关系的GRID显示,它的效率比ExpressQuantumGrid Suite还要高,不过功能不是很强。ExpressDBTree Suite 结合数据库表进行像WINDOWS中浏览器中树结构显示的件。ExpressOrgChart 结合数据库表进行组织结构显示的件。ExpressVerticalGrid Suite 表结构以垂直方式(卡片样式)的GRID显示,一般来说,GRID适合用来显示,而VerticalGrid适合用来编辑数据。下面的件还不知道有什么用,请有知道的介绍一下。ExpressFlowChartExpressSpreadSheet (includes Kylix support) 下面我们开始安装1、 首先关闭delphi7,如果您正在运行着它的话。 2、 安装ExpressLayout Control 1.1.11 for d7 ok3、 安装ExpressBars Suite 5.1.3 ok4、 安装ExpressDBTree Suite Version 1.3.1 ok5、 安装ExpressOrgChart 1.3.2 ok6、 安装ExpressFlowChart.v1.3.2 ok7、 安装DevExpress ExpressMasterView 1.2.1 ok8、 安装ExpressSpreadSheet (includes Kylix support) 1.1.12 ok9、 安装ExpressNavBar v1.3.1 ok10、安装ExpressPrinting System 3.1 ok11、安装ExpressQuantumGrid Suite 5.0 ok12、安装Express Scheduler Suite 1.0 13、安装ExpressQuantumTreeList Suite v4.0.2 14、安装ExpressVerticalGrid Suite 3.0.2 注:经过我反复试验发现Express Scheduler Suite 1.0 ExpressQuantumTreeList Suite v4.0.2 ExpressVerticalGrid Suite 3.0.2 与ExpressQuantumGrid Suite 5.0有冲突只要其中有任何两种件安装,就不能装入扩展件包ExpressExtendedEditors Library 5,Grid会少很多件。15、运行Delphi_7,出现第一个提示框后, 按否在Delphi 7中通过Tools->Environment Options->Library->Library path菜单路径打开Diredtories窗口。 将含有以下路径: ......Developer Express IncExpressDataControllerDelphi 7Lib ......Developer Express IncXP Theme ManagerDelphi 7Lib ......Developer Express IncCX LibraryDelphi 7Lib ......Developer Express IncExpressEditors Library 5Delphi 7Lib ......Developer Express IncExpressPageControl 2Delphi 7Lib ......Developer Express IncExpressQuantumGrid 5Delphi 7Lib 删除,重新添加为,或保留一份修改为: ......Developer Express IncExpressDataControllerDelphi 7Sources ......Developer Express IncXP Theme ManagerDelphi 7Sources ......Developer Express IncCX LibraryDelphi 7Sources ......Developer Express IncExpressEditors Library 5Delphi 7Sources ......Developer Express IncExpressPageControl 2Delphi 7Sources ......Developer Express IncExpressQuantumGrid 5Delphi 7Sources 18、到Grid 5.0目录下的完美补丁目录19、将以下2个文件:cxExtEditorsVCLD7.bpl dclcxExtEditorsVCLD7.bpl 解压到操作系统的System目录(注:W2K/WinXP中应为system32目录)中覆盖原文件。 20、将压缩包中ExpressEditors Library 5目录解压到Program FilesDeveloper Express Inc下覆盖原安装目录; 21、将压缩包中ExpressPageControl 2目录解压到Program FilesDeveloper Express Inc下覆盖原安装目录; 22、将压缩包中ExpressQuantumGrid 5目录解压到Program FilesDeveloper Express Inc下覆盖原安装目录; 23、将压缩包中Bpl目录解压到BorlandDELPHI7Projects下覆盖原目录。 24、到此全部安装完毕,对于ConvertGrid3Demo和ConvertGrid3MasterDetailDemo还必须同时安装“DevExpress ExpressQuantumGrid Suite v3.22 for Delphi7”,才行!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值