The Cxspreadsheetbook control uses

Source: Internet
Author: User

Because the project needs to read the data in Excel, and it can be edited, and requires an interface style adjustment, the control is studied.
Cxspreadsheetbook is an Excel control that can read data from Excel and control the cells of the control, enabling you to merge cells, set cell widths, set the cell's font size, font style, set cell text to center, and more. Here's the trick.

1: First define cell style

    1. Tstylevalue = (svalign, Svfontname, Svsize, Svbold, Svitalic, Svunderline, svstrikeout);
    2. Tstylevalueset = set of Tstylevalue;

The position of the text, the font name of the text, the size, whether it is bold, whether it is underlined, etc.

2: Merging cells

    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

Method of Use: Setmergedstatea (0,0,15,0,true);

3: Set the style of the cell text

  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. Var
  16. I, J:integer;
  17. Astyle:tfontstyles;
  18. Begin
  19. With Cx_statresult do
  20. Try
  21. BeginUpdate;
  22. With ActiveSheet do
  23. Begin
  24. For I: = Selectionrect.left to Selectionrect.right do
  25. For J: = Selectionrect.top to Selectionrect.bottom do
  26. With Getcellobject (I, J) do
  27. Try
  28. With Style do
  29. Begin
  30. Astyle: = Font.style;
  31. If svfontname in Avaluesset then
  32. Font.Name: = Afontname;
  33. If svsize in Avaluesset then
  34. Font.Size: = afontsize;
  35. If svalign in Avaluesset then
  36. Horztextalign: = aalign;
  37. SetValue (Svbold, Fsbold, Astyle);
  38. SetValue (Svitalic, Fsitalic, Astyle);
  39. SetValue (Svunderline, Fsunderline, Astyle);
  40. SetValue (Svstrikeout, Fsstrikeout, Astyle);
  41. Font.style: = Astyle;
  42. End
  43. Finally
  44. Free;
  45. End
  46. End
  47. Finally
  48. endupdate;
  49. Updatecontrol;
  50. End
  51. End

Use as follows:

    1. Cx_statresult.pages[0]. Selectcell (0,0,false);
    2. Setcellsstyle ([Svbold,svalign], hacenter, 0, ', [Fsbold]);

First select the cell and then call Setcellsstyle to format the cell

3: Control does not select a table, use the following statement:

    1. Cx_statresult.pages[0]. Selectcell ( -1,-1,false);


4: Set the width of a column

    1. Cx_statresult.pages[0]. cols.size[15]:=70;


5: Set the text of a cell

    1. Cell: = Cx_statresult.pages[0]. Getcellobject (15, 1);
    2. Cell.text:= ' remarks ';


6: Import Excel

    1. Cx_statresult.loadfromfile ();

The Cxspreadsheetbook control uses

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.