Reading the contents of Microsoft Visio (2010) doc in IronPython

别说谁变了你拦得住时间么 提交于 2019-12-02 19:41:10

问题


I have an assignment to write a program in IronPython, that reads a Visio (2010) Document, and outputs in CMD what objects are in the active page, and how they are connected to each other.

So far, I have managed to open the Visio Document, but I can't display what's in it. This is my code until now:

import sys
import clr
import System
clr.AddReference("Microsoft.Office.Interop.Visio")
import Microsoft.Office.Interop.Visio
IVisio = Microsoft.Office.Interop.Visio
visapp = IVisio.ApplicationClass()
doc = visapp.Documents.Open("C:\\Users\\hari\\Desktop\\PythonExamples\\helloworld.vsd") 
page = visapp.ActivePage

elements = page.GetContainers(0)

for entry in elements:
    print entry

doc.Close()
visapp.Visible =0
visapp.Quit()

I found the method GetContainers in MSDN http://msdn.microsoft.com/en-us/library/office/ff765392(v=office.15).aspx but it's not outputing anything about the shapes that exist in the document. Does someone maybe have an idea?


回答1:


You could start with something like this... it's pretty straightforward I suppose..

.......
.......
page = visapp.ActivePage

for shape in page.Shapes:
    if not shape.OneD:
        print shape.Name + " '" + shape.Text + "'"
        for connectedShapeId in shape.ConnectedShapes(2, ""):
            connectedShape = page.Shapes.ItemFromID[connectedShapeId]
            print " => " + connectedShape.Name + " '" + connectedShape.Text + "'"


来源:https://stackoverflow.com/questions/27439603/reading-the-contents-of-microsoft-visio-2010-doc-in-ironpython

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!