我有一个 Visio 模板,它有自己的模板(形状库)。想象一下,我有更多形状的模板;因此,我想删除模板 Visio 的模板,并想添加我的模板。我在互联网上搜索了很多,但找不到解决方案。我可以简单地将我的形状添加到模板文档模具中,但是,我想使用 Python 来执行此操作,因为我想使事情自动化,并且在每个模板中我都不想这样做。
在 office VBA 页面中,我发现了这一点,但无法在我的脚本中实现。(添加基于模板和模板的文档对象。)
这是链接:https ://docs.microsoft.com/en-us/office/vba/api/visio.documents.add
Public Sub AddDocument_Example()
Dim vsoDocument As Visio.Document
'Add a Document object based on the Basic Diagram template.
Set vsoDocument = Documents.Add("Basic Diagram.vst")
'Add a Document object based on a drawing (creates a copy of the drawing).
Set vsoDocument = Documents.Add("Myfile.vsd ")
'Add a Document object based on a stencil (creates a copy of the stencil).
Set vsoDocument = Documents.Add("Basic Shapes.vss")
'Add a Document object based on no template.
Set vsoDocument = Documents.Add("")
End Sub
我不知道删除当前模具可能会出现问题,因为模板 Visio 已经具有该模具的形状。
我乐于接受新的想法或解决方案。如果你帮助我,我将不胜感激。
我当前的代码:
import win32com.client
app = win32com.client.Dispatch("Visio.Application")
app.Visible = True
doc = app.Documents.Open("d:\\X.vsd") #Open template document
custom_stencil = app.Documents.Add("d:\\custom_stencil.vssx") #Trying to add custom stencil
page = app.ActivePage
#Show the all items in stencil
for shape in doc.Masters:
print(shape)