win32com +的Excel + Django的+ APACHE =问题 [英] win32com + Excel + Django + Apache = problem
问题描述
我有一些问题,在Web应用程序中打开Excel文档
阿帕奇(mod_wsgi的)/ Windows 2008的服务器下运行(有没有
当应用程序的django显影剂服务器上运行的问题 -
一个线程)。
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).
我的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()
错误消息:
( - 2147352567,'异常的发生。(0,u'Microsoft Office Excel中',
UMicrosoft Office Excel中无法访问文件'C:\\路径\\至
\\ file.xlsx。有几个可能的原因:文件名或路径
不存在。该文件被另一个程序。该
你试图保存工作簿具有相同名称作为当前打开的
工作簿,u'C:\\程序文件(x86)\\的Microsoft Office \\ OFFICE12 \\
\\ 1033 \\ XLMAIN11.CHM',0,-2146827284),无)
(-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)
我知道问题在什么地方线程局部的,但在哪里?
我使用pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)。
也许更改服务器就能解决问题?
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?
利布斯:Django的1.2,Apache 2.2的(mod_wsgi的),win32com(最新)
Libs: Django 1.2, Apache 2.2 (mod_wsgi), win32com (latest)
我希望有人能帮助我。
感谢您,
问候。
Thank You, regards.
推荐答案
在研究我找到了解决相同问题的时间。它无关pythoncom / win32com,但与事实Apache是作为服务运行。
该解决方案可以在这里找到:
After hours of researching the exact same problem I found the solution. It has nothing to do with pythoncom / win32com, but with the fact that the apache is running as a service. The solution can be found here:
<一个href=\"http://social.msdn.microsoft.com/Forums/en/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91\" rel=\"nofollow\">http://social.msdn.microsoft.com/Forums/en/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91
该解决方案由简单地使一个文件夹,给它写从相关(Apache)的用户权限:
The solution consists of simply making one folder and giving it write permissions from the relevant (apache) user:
64位Windows - 创建该文件夹:
64-bit windows - create this folder:
C:\Windows\SysWOW64\config\systemprofile\Desktop
32位Windows - 创建该文件夹:
32-bit windows - create this folder:
C:\Windows\System32\config\systemprofile\Desktop
这篇关于win32com +的Excel + Django的+ APACHE =问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!