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进程?

解决方案 »

  1.   

    可能是顺序不对,创建一个对象后,Excel.quit;Excel.Workbooks.close; 
    后,Excel 为空了,再Excel.Disconnect;对象不存在,当然会出错了,可以跟踪调试一下Excel
      

  2.   

      if not VarIsEmpty(FExcelApplication) then
      begin
        FExcelApplication.DisplayAlerts:=false;
        FExcelApplication.Quit;
      end;这样就行了
      

  3.   

    调用Sheet对象的Close方法就可以关闭了,关闭了再设置它为nil。
      

  4.   

    Excel.Workbooks.close; 
    Excel.quit;
      

  5.   

    根本就不行,通过另外一个函数调用有效果:function IsExcelInstall(): boolean; stdcall;
    begin
      if IsExcelInst() then
      begin
        Result := True;
        sleep(10000) //观察到excel退出了
      end
      else
        Result := false;
    end;