1,sleep(1000);
2,excelworkbook.close;
excelapplication.quit;//用excel控件,ole忘了,不经常使,这样就能关闭文件了
//用excel控件打开excel文件;
excelworkbook.connectto(excelapplication.workbook.open('c:/1/2.xls',null,null,12个,0) as _workbook);
excelworksheet.connectto(excelworkbook.activesheet as _worksheet);
那你用消息来处理吧,先得到打开的excel文件的窗体的句柄,这个可用通过标题来得到,
var hd:handle;
hd:=findwindow('','biaoti');
然后在用户关闭excel文件的窗体时发送wm_close消息,你就可以截获关闭的消息了,不知道对不对,刚过完年,头脑不太清醒,[],新年快乐,有什么事大家一起讨论好了,qq:26750660
给我点分我给你源代码怎么样。
procedure tfrmprint2.saveAsExcel;
var
fieldNum: integer;
i,j : integer;
exls,sheet: variant;
begin
try
exls:=createoleobject('Excel.application');
sheet:=createoleobject('excel.sheet');
except
application.MessageBox('请先安装MICROSOFT EXCEL!','提示',mb_ok+mb_iconinformation);
exit;
end;
sheet:=exls.workBooks.Add;
with query2 do
begin
DisableControls;
fieldNum := dbgrid1.fieldCount;
for i:=1 to fieldNum do
begin
exls.Cells[1,i].value:=Fields[i-1].FieldName;
end;
first;
i:=2;
while not eof do
begin
for j:=1 to fieldNum do
begin
exls.Cells[i,j]:=fields[j-1].AsString;
end;
next;
i:=i+1;
end;
EnableControls;
exls.visible:=true;
end;
end;