Visio 2010 加载项

发布于 2024-10-30 20:31:25 字数 445 浏览 2 评论 0原文

我正在编写 Visio 2010 加载项。 我需要处理文档并分析其中的所有对象。

首先我得到了 Visio

        IVisio.Application app;

        object visioObject = Marshal.GetActiveObject("Visio.Application");
        app = visioObject as IVisio.Application;

Now 的当前实例,如果

if (app.ActiveDocument != null)

我应该如何获取活动文档的所有元素? 我应该如何理解我正在分析的元素的类型? 如果此元素的类型为实体(对象关系),我应该如何访问所有列定义?

希望我清理了自己。

感谢您最终的提示!

I'm writing a Visio 2010 add-in.
I need to process the document and analyze all objects inside of it.

As first I got the current instance of Visio

        IVisio.Application app;

        object visioObject = Marshal.GetActiveObject("Visio.Application");
        app = visioObject as IVisio.Application;

Now, if

if (app.ActiveDocument != null)

How should I get all the elements of the active document?
How should I understand the type of the element I'm analyzing?
If this element is of type Entity (Object relational), how should I access all the columns definition?

Hope I cleared myself.

Thanks for eventual tips!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

゛清羽墨安 2024-11-06 20:31:26

我将从 Visio 2010 自动化参考开始,该参考可在线找到:

http://msdn .microsoft.com/en-us/library/ee861526.aspx

Visio 对象模型是一个相当庞大的野兽,需要一些时间来吸收和理解。但这些类都记录在 MSDN 上,因此您应该能够在那里找到参考资料、示例,甚至可能还有讨论论坛。

文档基本上由主形状和页面组成。它们都是 Shape 对象的容器。在形状内部,您将找到带有“截面”、“行”和“单元格”对象的形状表。每个单元格都有一个公式和一个值。

还有更多,但这可能足以让您开始。

I would start with the Visio 2010 Automation reference, found online at:

http://msdn.microsoft.com/en-us/library/ee861526.aspx

The Visio object model is quite a large beast, that takes some time to absorb and understand. But the classes are all documented on MSDN, so you should be able to find references, examples and probably even discussion forums up there.

A document basically consists of Master shapes, and Pages. These are both containers for Shape objects. And inside of shapes, you'll find the shapesheet with its Section, Row and Cell objects. Every Cell has a formula and a value.

There's more, too, but that might be enough to get you started.

鸢与 2024-11-06 20:31:26

一个简单的开始方法可能是以下单元测试,它将所有形状和名称写入控制台:

[TestMethod]
public void testVisio()
{
    Microsoft.Office.Interop.Visio.Application visioApp = null;
    try
    {
        //Create a new instance of Visio
        visioApp = new Microsoft.Office.Interop.Visio.Application();
        // Show Visio
        visioApp.Visible = true;

        foreach (Page page in visioApp.ActiveDocument.Pages)
        {
            foreach (Shape shape in page.Shapes)
            {
                Console.WriteLine(String.Format("Page {0}: Shape-Name: {1}", page.Name, shape.Name));
            }
        }
    }
    finally
    {
        //Close started application again
        visioApp.Quit();
        Marshal.ReleaseComObject(visioApp);
        visioApp = null;
    }
}

当然,您可以将 visioApp.ActiveDocument 替换为您在帖子中提到的引用。

更多信息可以在 MSDN 上找到,例如 http://msdn.microsoft.com/ en-us/library/gg617997.aspx 通常我建议稍微玩一下,您会找到所需的对象,例如形状具有可以存储用户属性的单元格等。
或者,如果没有,您可以提出更具体的问题。

An easy way of starting might be the following unit-test, that writes all shapes and names to the console:

[TestMethod]
public void testVisio()
{
    Microsoft.Office.Interop.Visio.Application visioApp = null;
    try
    {
        //Create a new instance of Visio
        visioApp = new Microsoft.Office.Interop.Visio.Application();
        // Show Visio
        visioApp.Visible = true;

        foreach (Page page in visioApp.ActiveDocument.Pages)
        {
            foreach (Shape shape in page.Shapes)
            {
                Console.WriteLine(String.Format("Page {0}: Shape-Name: {1}", page.Name, shape.Name));
            }
        }
    }
    finally
    {
        //Close started application again
        visioApp.Quit();
        Marshal.ReleaseComObject(visioApp);
        visioApp = null;
    }
}

Of course you can replace the visioApp.ActiveDocument with the reference you already mentioned in your posting.

More information can be found on MSDN, e.g. http://msdn.microsoft.com/en-us/library/gg617997.aspx and generally I recommend to just play around a bit, and you will find the objects required, e.g. shapes have cells where user-properties can be stored etc.
Or if not, you can ask a more specific question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文