win32com:打开工作簿类的方法失败



我正在尝试运行一个python脚本,该脚本首先使用凭据连接到网络驱动器,然后连接到MS访问Db文件&从包含网络驱动器上的源和目标excel文件路径的表中获取行。然后我在目标文件中执行宏。调用该脚本的批处理文件在交互模式下运行良好,但不能与windows服务或任务调度程序一起运行,因为它们抛出以下错误:

INFO | program.py | 34 | 13-01-2023 05:47 +0100 | The network connection could not be found.
More help is available by typing NET HELPMSG 2250.

INFO | program.py | 39 | 13-01-2023 05:47 +0100 | The command completed successfully.

INFO | program.py | 47 | 13-01-2023 05:47 +0100 | Connection to MS Access DB successfull
INFO | program.py | 55 | 13-01-2023 05:47 +0100 | Fetched rows from MS Access DB
INFO | program.py | 60 | 13-01-2023 05:47 +0100 | Closed MS Access DB Connection
INFO | program.py | 79 | 13-01-2023 05:47 +0100 | Executing VBScript with source file: source.xls & destination file: dest.xlsm
ERROR | program.py | 109 | 13-01-2023 05:47 +0100 | Error Occured
ERROR | program.py | 110 | 13-01-2023 05:47 +0100 | (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', 'Open method of Workbooks class failed', 'xlmain11.chm', 0, -2146827284), None)
Traceback (most recent call last):
File "C:programprogram.py", line 90, in <module>
xl.Workbooks.Open(destination_file, ReadOnly=1)
File "<COMObject <unknown>>", line 5, in Open
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', 'Open method of Workbooks class failed', 'xlmain11.chm', 0, -2146827284), None)
INFO | program.py | 112 | 13-01-2023 05:47 +0100 | 

错误相关代码:

xl = win32com.client.Dispatch("Excel.Application")
# xl.Visible = True
xl.Workbooks.Open(destination_file, ReadOnly=1)
xl.Application.Run("updaterun")
xl.Application.Quit() 
del xl

我没有找到任何解决这个问题的参考资料

试试这个:

xl.Workbooks.Open(destination_file, ReadOnly=1,CorruptLoad=1)

相关内容

  • 没有找到相关文章

最新更新