易截截图软件、单文件、免安装、纯绿色、仅160KB

delphi怎么关闭excel进程?

    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.quit;Excel.Workbooks.close;
后,Excel 为空了,再Excel.Disconnect;对象不存在,当然会出错了,可以跟踪调试一下Excel

  if not VarIsEmpty(FExcelApplication) then
  begin
    FExcelApplication.DisplayAlerts:=false;
    FExcelApplication.Quit;
  end;

这样就行了

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

Excel.Workbooks.close;
Excel.quit;

根本就不行,通过另外一个函数调用有效果:

function IsExcelInstall(): boolean; stdcall;
begin
  if IsExcelInst() then
  begin
    Result := True;
    sleep(10000) //观察到excel退出了
  end
  else
    Result := fal


相关问答:

ACCESS的自定义函数在delphi里怎么用呢...

我在模块里自定义了一个函数:stradd()

可是在adoquery1.sql.add('select stradd(author) from book');
时提示stradd未定义...

这个问题有什么办法可以解决的吗? 非常感激!


(在A ......

Delphi中数据库查询的疑惑

昨晚在Delphi数据库查询中遇到了一个疑惑。代码如下:
procedure TFormSearchAchievement.ComboBoxXYChange(Sender: TObject);
var
  XY : string;
begin
  XY := comboboxxy.Items[comboboxx ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号