windows - Python调用win32com.client.Dispatch('Word.Application')报错
高洛峰
高洛峰 2017-04-18 09:05:10
0
1
1519

我现在使用Python进行office文件操作,但是在调用win32com.client.Dispatch模块时报错,代码如下:

import win32com
from win32com.client import Dispatch,constants
w = win32com.client.Dispatch('Word.Application')

错误信息如下所示:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:Python27libsite-packageswin32comclient__init__.py", line 95, in Dispatch

dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)

File "C:Python27libsite-packageswin32comclientdynamic.py", line 114, in _GetGoodDispatchAndUserName

return (_GetGoodDispatch(IDispatch, clsctx), userName)

File "C:Python27libsite-packageswin32comclientdynamic.py", line 91, in _GetGoodDispatch

IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)

com_error: (-2147221164, 'xc3xbbxd3xd0xd7xa2xb2xe1xc0xe0', None, None)

我有点看不太懂,也没查到太多有用信息,各位有没有遇到类似问题的,请赐教。

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
左手右手慢动作

The cause of the problem was not found, but it was solved using other methods.
The environment where this problem occurs is Python 2.7 32-bit, pywin32 32-bit, win7 64-bit, and office 2007.
I changed to another environment on another machine, Python 2.7 64-bit, pywin32-220.win-amd64-py2.7 64-bit, win7 64-bit, office 2007 (newly installed).
The second environment test passed.
Cause analysis: 1. The first environment is on an office computer with a lot of software installed, including anti-virus software and DLP encryption software. I don’t know if it will have any impact on the office program, which may lead to errors in calling win32com.
2. The system environment must be consistent with the software configuration, that is, both 64-bit or 32-bit. Because there may be problems with 32-bit Python modules calling 64-bit office programs.
The above are my thoughts, everyone is welcome to add.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template