Python Win32com未发送excel,表示';服务器执行失败';

Python Win32com未发送excel,表示';服务器执行失败';,python,excel,win32com,Python,Excel,Win32com,我最初的剧本是: 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,ReadOn

我最初的剧本是:

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)
回溯(最近一次呼叫最后一次):
文件“C:/Users/cevans/PycharmProjects/RigLocatorMapPull/Pipe_StorageRefresh.py”,第17行,在
复习者()
文件“C:/Users/cevans/PycharmProjects/RigLocatorMapPull/Pipe_StorageRefresh.py”,第10行,在Refresh中
xl=win32com.client.Dispatch(“Excel.Application”)
文件“C:\Python27\lib\site packages\win32com\client\\uuuu init\uuuu.py”,第95行,在分派中
调度,用户名=动态。\ GetGoodDispatchAndUserName(调度,用户名,clsctx)
文件“C:\Python27\lib\site packages\win32com\client\dynamic.py”,第104行,位于_GetGoodDispatchAndUserName中
返回(_GetGoodDispatch(IDispatch,clsctx),用户名)
文件“C:\Python27\lib\site packages\win32com\client\dynamic.py”,第84行,在\u GetGoodDispatch中
IDispatch=pythoncom.CoCreateInstance(IDispatch,None,clsctx,pythoncom.IID_IDispatch)
pywintypes.com_错误:(-2146959355,‘服务器执行失败’,无,无)

一个解决方案是重新启动windows操作系统(完成重新安装),因为excel的windows操作系统注册表似乎有错误。我发现这是使用win32com时出现其他“服务器执行失败”类型错误的原因。

我的第一个猜测是,这与excel有关,因为我已经使用Word和其他应用程序进行了测试,效果良好。