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

1.4k views Asked by At

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?

2

There are 2 answers

0
Benjamin Gudehus On BEST ANSWER

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.

0
stengbiegel On

Looks like you are missing

xls.release();

like it is done here.