我只是想让 xlwings 使用:
Windows 8.1
Python 2.7.5
Excel 2013
xlwings 安装正常(它导入时没有错误消息)。我尝试过使用 IDLE 并使用 ipython/Python 2.7.6 并且在两者下我都得到了类似的错误跟踪,但我并没有真正遵循。下面是 IDLE 会话的输出:
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> from xlwings import Workbook, Range
>>> wb = Workbook("C:\Users\Alan\Documents\Xlsaves\Test.xlsx")
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
wb = Workbook("C:\Users\Alan\Documents\Xlsaves\Test.xlsx")
File "C:\Python27\lib\site-packages\xlwings\main.py", line 52, in __init__
self.xl_app, self.xl_workbook = xlplatform.open_workbook(self.fullname)
File "C:\Python27\lib\site-packages\xlwings\_xlwindows.py", line 93, in open_workbook
xl_app = _get_latest_app()
File "C:\Python27\lib\site-packages\xlwings\_xlwindows.py", line 89, in _get_latest_app
return dynamic.Dispatch('Excel.Application')
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 122, in Dispatch
IDispatch, userName = _GetGoodDispatchAndUserName(IDispatch,userName,clsctx)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 114, in
_GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
com_error: (-2147221005, 'Invalid class string', None, None)
ipython下的结果类似,也以com错误结束。以上似乎表明python正在寻找xlwings脚本文件。我试过关闭和打开 excel;没有指定 excel 文件并且具有上述完整文件路径。我确定我遗漏了一些明显的东西,但我不知道是什么。希望有人可以提供帮助。