[python-win32] Closing Excel object.

Victor Hadianto victorh@nuix.com.au
Tue, 15 Oct 2002 10:33:20 +1000


I have a python script running in an Apache web server that receives a
binary file using form-post, convert it into a text file and print the
result back to the browser.

The code is like this:

form = cgi.FieldStorage()
item = form["file1"]

value = tempfile.mktemp(".xls")
convertedValue = tempfile.mktemp(".txt")

### Save files into disk ###

x = win32com.client.Dispatch("Excel.Application")
x.Workbooks.Open(value)
x.ActiveWorkbook.SaveAs(convertedValue, -4158, 0)

x.Quit()
del x

### Print text file to browser

os.remove(value)
os.remove(convertedValue)


Now the problem is even if I did x.Quit(), I can't actually "close" the
Excel application. In my TaskManager I still see the Excel process running.
The same trick works fine with Microsoft Word!

Does anyone has any idea how to close Excel object using Python?

Any help will be greatly appreciated.

Victor