开发者

Scriptom (groovy) leaves Excel process running - am I doing something wrong?

开发者 https://www.devze.com 2022-12-23 18:59 出处:网络
I am using the Scriptom extension to Groovy 1.7.0 to automate some processing using Excel 2007 under Windows XP.

I am using the Scriptom extension to Groovy 1.7.0 to automate some processing using Excel 2007 under Windows XP.

This always seems to leave an Excel process running despite my calling quit on the excel activeX object. (There is a passing reference to this phenomenon in the Scriptom example documentation too.)

Code looks like:


import org.codehaus.groovy.scriptom.ActiveXObject;
def xls = new ActiveXObject("Excel.开发者_运维技巧Application")
xls.Visible = true

// do xls stuff

xls.Quit()

The visible excel window does disappear but an EXCEL process is left in the task manager (and more processes pile up with each run of the script).

There are no error message or exceptions.

Can anyone explain why the Excel process is left behind and is there any way to prevent it from happening?


This works:

xls.Quit()
Scriptom.releaseApartment()

The javadocs state:

In some cases, the JVM can close before everything is cleaned up, which can leave automation servers (especially Excel) hanging. Call this before your script exits to get correct behavior from automation servers.


Looks like you are missing

xls.release();

like it is done here.

0

精彩评论

暂无评论...
验证码 换一张
取 消