在ISAPI中用CreateOleObject('Excel.Application')方式使用了Excel,如何确保在使用完毕或出现异常之后能正常释放Excel进程?
我这样写,出现异常之后会有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;