I have some problem with opening Excel document in web application running under Apache(mod_wsgi)/Windows 2008 Server (there is no problem when the application is running on django developer server - one thread).
My code:
def my_view(request):
import pythoncom
from win32com.client import DispatchEx
pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)
xl = win32com.client.dynamic.Dispatch('Excel.Application')
xl.DisplayAlerts = False
xl.Visible = 0
doc = xl.Workbooks.Open("C:\\path\\to\\file.xlsx")
doc.Saved = True
...
wb.Close(SaveChanges=0)
xl.Quit()
pythoncom.CoUninitialize()
Error message:
(-2147352567, 'Exception occurred.', (0, u'Microsoft Office Excel', u"Microsoft Office Excel cannot access the file 'C:\path\to \file.xlsx'. There are several possible reasons: The file name or path does not exist. The file is being used by another program. The workbook you are trying to save has the same name as a currently open workbook.", u'C:\Program Files (x86)\Microsoft Office\Office12\ \1033\XLMAIN11.CHM', 0, -2146827284), None)
I know that problem is localized somewhere in threading, but where? I'm using pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED). Maybe changing the server will solve the problem?
Libs: Django 1.2, Apache 2.2 (mod_wsgi), win32com (latest)
I hope somebody can help me.
Thank You, regards.