Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

Looks like you are missing

xls.release();

like it is done here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top