cxSpreadSheetBook控件使用:

1、新建工程,拖入四个Button,cxSpreadSheetBook、dxComponentPrinter、dxPSEngineControlle控件,窗口如图:

2、对四个Button录入代码:

unit Unit1; 

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,

  StdCtrls, cxSSheet, ExtCtrls, dxPSGlbl, dxPSUtl, dxPSEngn, dxPrnPg,

  dxBkgnd, dxWrap, dxPrnDev, dxPSCompsProvider, dxPSFillPatterns,

  dxPSEdgePatterns, dxPSPDFExportCore, dxPSPDFExport, cxDrawTextUtils,

  dxPSPrVwStd, dxPSPrVwAdv, dxPSPrVwRibbon, dxPScxPageControlProducer,

  dxPScxSSLnk, dxPScxEditorProducers, dxPScxExtEditorProducers, dxPSCore,

  dxPSBaseGridLnk, dxPScxGridLnk, dxPScxGridLayoutViewLnk, dxPScxCommon,

  dxPSTextLnk;

type

  TForm1 = class(TForm)

    Panel1: TPanel;

    cxSpreadSheetBook1: TcxSpreadSheetBook;

    Button1: TButton;

    Button2: TButton;

    Button3: TButton;

    dxComponentPrinter1: TdxComponentPrinter;

    dxComponentPrinter1Link1: TdxSpreadSheetBookReportLink;

    dxPSEngineController1: TdxPSEngineController;

    Button4: TButton;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);

    procedure Button4Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end; 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

  //装入按扭

procedure TForm1.Button1Click(Sender: TObject);

begin

   //装载文件

   cxSpreadSheetBook1.LoadFromFile('f:\绍兴市公立医院综合改革监测(上虞201501).xls')    //cxSpreadSheet1.LoadFromFile('f:\绍兴市公立医院综合改革监测(上虞201501).xls')

end;

//保存按扭

procedure TForm1.Button2Click(Sender: TObject);

begin

   cxSpreadSheetBook1.SaveToFile('f:\绍兴市公立医院综合改革监测(上虞201501).xls');

end;

//打印按扭

procedure TForm1.Button3Click(Sender: TObject);

begin

  dxComponentPrinter1Link1.Preview(true);

  //dxComponentPrinter1.Print(True, nil, dxComponentPrinter1Link1);

end;

//取数按扭

procedure TForm1.Button4Click(Sender: TObject);

var

  CellObject: TcxSSCellObject;

begin

 cxSpreadSheetBook1.ActivePage := 0;//表页为第一页

 //CellObject := cxSpreadSheetBook1.ActiveSheet.getCellObject(4, 6);

 //ShowMessage(CellObject.Text);

  with cxSpreadSheetBook1.ActiveSheet.GetCellObject(4,6) do

  begin

    try

      Text := '100';//在第5列第7行显示100

    finally

      Free;                                                // and free it (important!)

    end;

  end;

end;

end.

3、执行窗口如图: