coInitialize(nil);
Excel := CreateOleObject('Excel.Application');
Excel.Workbooks.close;
Excel.quit;
// Excel.Disconnect; //这句出错
Excel := unassigned;
counInitialize;
// Exceltemp.Disconnect;
//if not VarIsEmpty(Exceltemp) then Exceltemp.quit;
sleep(10000); //延时,便于观察excel.exe进程是否关闭
Result := True;
exit;上面的代码怎么不能关闭excel进程?
Excel := CreateOleObject('Excel.Application');
Excel.Workbooks.close;
Excel.quit;
// Excel.Disconnect; //这句出错
Excel := unassigned;
counInitialize;
// Exceltemp.Disconnect;
//if not VarIsEmpty(Exceltemp) then Exceltemp.quit;
sleep(10000); //延时,便于观察excel.exe进程是否关闭
Result := True;
exit;上面的代码怎么不能关闭excel进程?
后,Excel 为空了,再Excel.Disconnect;对象不存在,当然会出错了,可以跟踪调试一下Excel
begin
FExcelApplication.DisplayAlerts:=false;
FExcelApplication.Quit;
end;这样就行了
Excel.quit;
begin
if IsExcelInst() then
begin
Result := True;
sleep(10000) //观察到excel退出了
end
else
Result := false;
end;