在ISAPI中用CreateOleObject('Excel.Application')方式使用了Excel,如何确保在使用完毕或出现异常之后能正常释放Excel进程?

kingbenz 2004-12-23 10:11:07
我这样写,出现异常之后会有Excel进程驻留在内存:
Var
ExcelApp, ExcelBook, ExcelSheet: Variant;
begin
Try
ExcelApp := CreateOleObject('Excel.Application');
ExcelBook := ExcelApp.WorkBooks.Open(FXlsFile);
ExcelSheet := ExcelBook.Sheets.Item[1];

...........

ExcelBook.Close;
ExcelApp.Quit;
ExcelSheet:=Unassigned;
ExcelBook:=Unassigned;
ExcelApp:=Unassigned;
Except
On E:Exception do
begin
ExcelBook.Close;
ExcelApp.Quit;
ExcelSheet:=Unassigned;
ExcelBook:=Unassigned;
ExcelApp:=Unassigned;
end;
End;
...全文
188 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
steaddream 2005-01-13
  • 打赏
  • 举报
回复
try
....
except
ExcelBook.Close(false,emptyparam,emptyparam);
ExcelApp.Quit;
ExcelSheet:=Unassigned;
ExcelBook:=Unassigned;
ExcelApp:=Unassigned;
end;
xiaoluzhu0420 2004-12-27
  • 打赏
  • 举报
回复
顶一下,散点分:)

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧