无法使用 Python 打开 Visio 文档 [英] Cannot open Visio document with Python

查看:62
本文介绍了无法使用 Python 打开 Visio 文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Python 在 Visio 中执行一些自动化操作.我可以打开 Visio 应用程序并创建一个新文档,但无法打开现有文档.这是我正在尝试的代码.

I am attempting to do some automation in Visio using Python. I am able to open the Visio application and create a new document, but cannot open an existing document. Here is the code that I am trying.

  import win32com.client

  visio = win32com.client.Dispatch("Visio.Application")  # this works
  doc = visio.Documents.Open("C:\Users\username\test.vsd") # nope

我返回的错误是

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<COMObject <unknown>>", line 3, in OpenEx
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft Visio', u'\n\nFile not found.', None, 0, -2032465466), None)

我也尝试过使用 visio.Documents.OpenEx 并得到相同的答案.有什么想法吗?

I have tried using visio.Documents.OpenEx as well and get the same answer. Any thoughts?

推荐答案

我猜这可能有用 -

doc = visio.Documents.Open("C:\\Users\\username\\test.vsd")

这篇关于无法使用 Python 打开 Visio 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆