我的测试代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtnrs, Menus, Excel2000, OleServer;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
OleContainer1: TOleContainer;
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Exapp, RangeE, Exappsheet: OleVariant;
BookName : String;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
if Olecontainer1.State <> osEmpty then Olecontainer1.DestroyObject;
Olecontainer1.CreateObjectFromFil('d:/application/FS_Water/aboutOLEMenu/ole.xls',false);
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
Olecontainer1.AutoActivate :=aaGetFocus;
Olecontainer1.DoVerb(ovPrimary);
Exapp:=OleContainer1.OleObject;
exapp:=Exapp.Application;
BookName := Exapp.Activeworkbook.Name;
Exapp.Workbooks[BookName].Saved := True;
end;