gpt4 book ai didi

python - Win32com 没有发送 excel,说 'Server execution failed'

转载 作者:行者123 更新时间:2023-12-04 21:03:48 30 4
gpt4 key购买 nike

我的初始脚本是:

import win32com.client
import os

file1= r'C:\\Users\cevans\Desktop\models1\file.xlsm'

def refresher():
if os.path.exists(file1):
xl = win32com.client.Dispatch("Excel.Application")
xl.Workbooks.Open(Filename=file1,ReadOnly=1)
xl.Visible = True
xl.Application.Run('Report_Tablerefresh1')
xl.Workbooks(1).Close(SaveChanges=1)
xl.Application.Quit()
del xl
refresher()

我在尝试执行简单的 excel 调度时收到此错误,奇怪的是脚本已经运行了几个星期,然后弹出此错误。有什么建议么?
Traceback (most recent call last):
File "C:/Users/cevans/PycharmProjects/RigLocatorMapPull/Pipe_StorageRefresh.py", line 17, in <module>
refresher()
File "C:/Users/cevans/PycharmProjects/RigLocatorMapPull/Pipe_StorageRefresh.py", l ine 10, in refresher
xl = win32com.client.Dispatch("Excel.Application")
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 104, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 84, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2146959355, 'Server execution failed', None, None)

最佳答案

一种解决方案是重新启动 Windows 操作系统(进行完全重新安装),因为使用 excel 的 Windows 操作系统注册表似乎存在错误。我发现这是使用 win32com 导致其他“服务器执行失败”类型错误的原因。

关于python - Win32com 没有发送 excel,说 'Server execution failed',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29564737/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com