[python-win32] excel termination
Tim Golden
tim.golden at viacom-outdoor.co.uk
Wed Apr 14 06:48:51 EDT 2004
GA> I have written a programme which opens excel,
GA> extracts some data from it and then again closes it.
GA> The problem is when I look in taskmanager I can still
GA> see the process (excel.exe).
Well it's difficult to tell without seeing exact code,
but the code snippet below shows that the Excel process
does close if (a) you delete the reference to the
COM object (in my code, the xl variable) and (b) wait
a little bit for things to catch up with themselves.
I get the following output:
C:\temp>excel.py
0 Excel processes running
1 Excel processes running
1 Excel processes running
0 Excel processes running
TJG
<code>
import win32com.client
import wmi
import time
c = wmi.WMI ()
print len (c.Win32_Process (Name="excel.exe")), "Excel processes running"
xl = win32com.client.Dispatch ("Excel.Application")
print len (c.Win32_Process (Name="excel.exe")), "Excel processes running"
# Do stuff with xl
xl.Quit ()
time.sleep (0.5)
print len (c.Win32_Process (Name="excel.exe")), "Excel processes running"
del xl
time.sleep (0.5)
print len (c.Win32_Process (Name="excel.exe")), "Excel processes running"
</code>
________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
More information about the Python-win32
mailing list