问题
I'm simply trying to get xlwings working with:
Windows 8.1
Python 2.7.5
Excel 2013
xlwings installed OK (it imports without error messages). I've tried using IDLE and also using ipython/Python 2.7.6 and under both I get similar error traces which I don't really follow. Here is the output from the IDLE session:
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)
The results under ipython are similar and also end in a com error. The above seems to indicate that python is finding the xlwings script file. I've tried with excel closed and open; with no excel file specified and with the full file path as above. I'm sure I've omitted something obvious but I don't know what. Hopefully someone can help.
来源:https://stackoverflow.com/questions/27371276/xlwings-gives-invalid-class-string-error