win32api文件路径

发布于 2025-02-03 10:32:49 字数 784 浏览 5 评论 0原文

我有一个使用Win32API重新计算Excel文件的脚本。它可以无错误。

当我尝试通过pywinrm远程运行相同的脚本时,我会发现一个错误:

错误:com_error:((-2147352567,'异常发生。 'xlmain11.chm',0,-2146827284),无)

有什么问题?

import winrm
host = 'myhost'
domain = 'mydomain'
user = 'myuser'
password = 'mypassword'
session = winrm.Session(host, auth=('{}@{}'.format(user,domain), password), transport='ntlm')

result = session.run_ps('python script.py')

远程计算机上的script.py

import win32com.client

xlapp = win32com.client.DispatchEx("Excel.Application")
xlapp.Visible = True

path = "C:\\Users\\MyUser\\Desktop\\excel\\test_file.xlsx"
wb = xlapp.Workbooks.open(path)

文件在此路径上存在。它可以通过open('Path',rb)读取。如果我在远程计算机上运行相同的代码(手动无需WinRM),则没有问题。

I have a script that re-calculates an Excel file using win32api. It works without errors.

When I try to run the same script remotely through pywinrm, I get an error:

Error: com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', "Sorry, we couldn't find test1.xlsm. Is it possible it was moved, renamed or deleted?", 'xlmain11.chm', 0, -2146827284), None)

What can be the problem?

import winrm
host = 'myhost'
domain = 'mydomain'
user = 'myuser'
password = 'mypassword'
session = winrm.Session(host, auth=('{}@{}'.format(user,domain), password), transport='ntlm')

result = session.run_ps('python script.py')

script.py on remote machine

import win32com.client

xlapp = win32com.client.DispatchEx("Excel.Application")
xlapp.Visible = True

path = "C:\\Users\\MyUser\\Desktop\\excel\\test_file.xlsx"
wb = xlapp.Workbooks.open(path)

The file exists on this path. It can be read via open('path', rb). If I run the same code on a remote machine (without winrm, manually), there is no problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文