问题
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
The error I get back is
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)
I have tried using visio.Documents.OpenEx as well and get the same answer. Any thoughts?
回答1:
I am guessing that this might work -
doc = visio.Documents.Open("C:\\Users\\username\\test.vsd")
回答2:
Instead of forward slashes you can use backward ones
doc = visio.Documents.Open(r"C:\Users\username\test.vsd")
or
doc = visio.Documents.Open("C:/Users/username/test.vsd")
来源:https://stackoverflow.com/questions/26001984/cannot-open-visio-document-with-python