A
Apollo_BD
Unregistered / Unconfirmed
GUEST, unregistred user!
类定义如下:
unit UnitOA;
interface
Uses ComObj,Dialogs,SysUtils,Classes;
Type
TOA=class(TComponent)
Public
Function Open(PathName:string):Boolean;virtual;abstract;
End;
Type
ExOption=(Nosave,SaveAs);
Type
TExcel=Class(TOA)
Private
ExcelApp:variant;
function GetTitle: string;
function GetVisible: boolean;
procedure SetTitle(const Value: string);
procedure Setvisible(const Value: boolean);
Published
Constructor Create;
property Tilte:string Read GetTitle Write SetTitle;
Property Visible:boolean Read GetVisible Write Setvisible stored False;
Procedure AddWorkBooks;
Procedure CloseWorkBooks;
Function Open(PathName:String):Boolean;override;
Function ExitExcel(Option:ExOption):Boolean;
Procedure FillCell(X,Y:integer;Cell:Variant);
Function Bcellname(X:integer):string;
End;
Procedure Register;
implementation
Procedure Register;
Begin
RegisterComponents('MyExcel',[TExcel]);
end;
{ TExcel }
procedure TExcel.AddWorkBooks;
begin
ExcelApp.WorkBooks.Add;
end;
function TExcel.Bcellname(X:integer): string;
var
I,J:Integer;
begin
IF X<=26
Then Result:=Char(X+64)
Else Begin
I:=ABS((X-26) Div 26)+1;
J:=((X-26) Mod 26);
If ((X-26) Mod 26)=0
Then begin
I:=I-1;
J:=26;
End;
Result:=Char(I+64)+Char(J+64);
End;
End;
procedure TExcel.CloseWorkBooks;
begin
ExcelApp.WorkBooks.Close;
end;
constructor TExcel.Create;
begin
Try
ExcelApp:=CreateOLeObject('Excel.Application');
ExcelApp.Visible:=False;
Except
Showmessage('不能调用Excel!');
End;
end;
function TExcel.ExitExcel(Option:ExOption):Boolean;
begin
ExcelApp.Quit;
end;
procedure TExcel.FillCell(X,Y: integer; Cell: Variant);
begin
ExcelApp.Cells[x,y]:=Cell;
end;
function TExcel.GetTitle: string;
begin
Result:=ExcelApp.Caption;
end;
function TExcel.GetVisible: boolean;
begin
Result:=ExcelApp.Visible;
end;
function TExcel.Open(PathName: String): Boolean;
begin
IF Fileexists(Pathname)
Then Begin
ExcelApp.WorkBooks.Open(Pathname);
Result:=True;
End Else Result:=False;
End;
procedure TExcel.SetTitle(const Value: string);
begin
ExcelApp.Caption:=Value;
end;
procedure TExcel.Setvisible(const Value: boolean);
begin
ExcelApp.Visible:=Value;
end;
Initialization;
end.
可以安装到Vcl面版上,但是当我把它拖到新建的窗体上时总是提示"Invalid Variant Operation",另外我还想知道控件安装到Vcl面版后如何自己定义其显示的图标(默认的太难看了)
unit UnitOA;
interface
Uses ComObj,Dialogs,SysUtils,Classes;
Type
TOA=class(TComponent)
Public
Function Open(PathName:string):Boolean;virtual;abstract;
End;
Type
ExOption=(Nosave,SaveAs);
Type
TExcel=Class(TOA)
Private
ExcelApp:variant;
function GetTitle: string;
function GetVisible: boolean;
procedure SetTitle(const Value: string);
procedure Setvisible(const Value: boolean);
Published
Constructor Create;
property Tilte:string Read GetTitle Write SetTitle;
Property Visible:boolean Read GetVisible Write Setvisible stored False;
Procedure AddWorkBooks;
Procedure CloseWorkBooks;
Function Open(PathName:String):Boolean;override;
Function ExitExcel(Option:ExOption):Boolean;
Procedure FillCell(X,Y:integer;Cell:Variant);
Function Bcellname(X:integer):string;
End;
Procedure Register;
implementation
Procedure Register;
Begin
RegisterComponents('MyExcel',[TExcel]);
end;
{ TExcel }
procedure TExcel.AddWorkBooks;
begin
ExcelApp.WorkBooks.Add;
end;
function TExcel.Bcellname(X:integer): string;
var
I,J:Integer;
begin
IF X<=26
Then Result:=Char(X+64)
Else Begin
I:=ABS((X-26) Div 26)+1;
J:=((X-26) Mod 26);
If ((X-26) Mod 26)=0
Then begin
I:=I-1;
J:=26;
End;
Result:=Char(I+64)+Char(J+64);
End;
End;
procedure TExcel.CloseWorkBooks;
begin
ExcelApp.WorkBooks.Close;
end;
constructor TExcel.Create;
begin
Try
ExcelApp:=CreateOLeObject('Excel.Application');
ExcelApp.Visible:=False;
Except
Showmessage('不能调用Excel!');
End;
end;
function TExcel.ExitExcel(Option:ExOption):Boolean;
begin
ExcelApp.Quit;
end;
procedure TExcel.FillCell(X,Y: integer; Cell: Variant);
begin
ExcelApp.Cells[x,y]:=Cell;
end;
function TExcel.GetTitle: string;
begin
Result:=ExcelApp.Caption;
end;
function TExcel.GetVisible: boolean;
begin
Result:=ExcelApp.Visible;
end;
function TExcel.Open(PathName: String): Boolean;
begin
IF Fileexists(Pathname)
Then Begin
ExcelApp.WorkBooks.Open(Pathname);
Result:=True;
End Else Result:=False;
End;
procedure TExcel.SetTitle(const Value: string);
begin
ExcelApp.Caption:=Value;
end;
procedure TExcel.Setvisible(const Value: boolean);
begin
ExcelApp.Visible:=Value;
end;
Initialization;
end.
可以安装到Vcl面版上,但是当我把它拖到新建的窗体上时总是提示"Invalid Variant Operation",另外我还想知道控件安装到Vcl面版后如何自己定义其显示的图标(默认的太难看了)