Var
xlsname:string;
ExcelApp: Variant;
olecon: TOleContainer;
begin
Olecon:= TOleContainer.Create(self);
Olecon.AllowInPlace:=true;
Olecon.align:=alclient;
Olecon.Parent:= panel1;
//OleCon.InsertObjectDialog;
//Olecon.CreateObject('Excel.Application',false);
OleCon.AutoActivate:=aaManual;//!!!
xlsname:=ExtractFilePath(Application.ExeName) + 'e.xls';
OleCon.CreateObjectFromFile(xlsname,False);
//oleCon.CreateObject('Excel.Sheet',false);
{Olecon.CreateObject('Excel.Application',false);//excel.sheet',false);
//或选择导入一个excel文件来创建OLE对象:
xlsname:=ExtractFilePath(Application.ExeName) + 'e.xls';
//Olecon.CreateObjectFromFile(xlsname,false);
//最好隐藏excel的几个工具条,这样就好象是嵌在你的程序中的一个表而已了:
Olecon.OleObject.application.CommandBars['Standard'].Visible:=false;
Olecon.OleObject.application.CommandBars['Formatting'].Visible:=false;
Olecon.OleObject.application.CommandBars['Reviewing'].Visible:=false;
ExcelApp:= Olecon.OleObject.application;
ExcelApp.WorkBooks.Open(xlsname);
//然后显示并激活excel表,对TOleContainer定义的对象:
OleCon.Visible:=True;
ExcelApp.Visible:=True;
//OleCon.DoVerb(ovShow);
//OleCon.SetFocus;
//Olecon.doverb(0); }