簡體   English   中英

使用win32com庫python的無效類字符串

[英]invalid class string using win32com library python

我編寫了流程來調度excel應用程序。 我在python中使用了win32庫,並這樣寫:

import win32com.client as win32
import pywinauto

excel = win32.gencache.EnsureDispatch('Excel.Application'

由於這一行,我得到了這個錯誤:

K:\venv\Scripts\python.exe K:/test_results.efrat.py
Traceback (most recent call last):
  File "K:\venv\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
    IDispatch = pythoncom.connect(IDispatch)
win32.types.com_error: (-2147221005, 'Invalid class string', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "K:/test_results.efrat.py", line 8, in <module>
    excel = win32.gencache.EnsureDispatch('Excel.Application')
  File "K:\venv\lib\site-packages\win32com\client\gencache.py", line 527, in EnsureDispatch
    disp = win32com.client.Dispatch(prog_id)
  File "K:\venv\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "K:\venv\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "K:\venv\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
win32.types.com_error: (-2147221005, 'Invalid class string', None, None)

Process finished with exit code 1

有誰知道可能是什么問題? 我的庫包中安裝了pywin32和pypiwin32。

這對我來說可以。 從站點程序包中刪除pywin32,然后嘗試從以下URL安裝pywin32.exe:

https://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM