c# – 如何在Visio中读取Shape的属性

c# – 如何在Visio中读取Shape的属性,第1张

概述我有以下任务.我正在Studio 2010中的C#上为Visio 2010编写一个加载项. 假设我打开了一个图表.我在这个图中有任何形状的形状(让我们尝试管理一个开头的形状).问题是如何阅读这种形状的任何属性?我应该使用哪种API? 基本算法: >扫描打开的文档以获取形状 >如果文档中有任何形状,则返回所有形状的数组(或列表)(如果当前文档中没有形状,则返回null) >运行形状数组并读取每个元素 我有以下任务.我正在Studio 2010中的C#上为Visio 2010编写一个加载项.
假设我打开了一个图表.我在这个图中有任何形状的形状(让我们尝试管理一个开头的形状).问题是如何阅读这种形状的任何属性?我应该使用哪种API?

基本算法:

>扫描打开的文档以获取形状
>如果文档中有任何形状,则返回所有形状的数组(或列表)(如果当前文档中没有形状,则返回null)
>运行形状数组并读取每个元素的任何属性(这将很有可能写入/修改属性)

(代码示例将不胜感激)

解决方法 我假设你通过属性引用Shape Data,它曾经在UI中被称为Custom PropertIEs,并且在API中仍然知道该名称.

如果您不熟悉shapesheet,则应首先在shapesheet中查看具有自定义属性的形状,以查看属性的定义方式.请参阅“What happened to the ShapeSheet?”以了解如何在Visio 2010中打开shapesheet.

以下示例程序应该可以帮助您入门.此示例假定您已在PC上安装了Visio Primary Interop Assembly,并且您已将裁判包含在项目中的Microsoft.Office.Interop.Visio中.

namespace VisioEventsExample{    using System;    using Microsoft.Office.Interop.Visio;    class Program    {        public static voID Main(string[] args)        {            // Open up one of Visio's sample drawings.            Application app = new Application();            document doc = app.documents.Open(                @"C:\Program files\Microsoft Office\Office14\visio content33\ASTMGT_U.VST");            // Get the first page in the sample drawing.            Page page = doc.Pages[1];            // Start with the collection of shapes on the page and             // print the propertIEs we find,printPropertIEs(page.Shapes);        }        /* This function will travel recursively through a collection of          * shapes and print the custom propertIEs in each shape.          *          * The reason I don't simply look at the shapes in Page.Shapes is          * that when you use the Group command the shapes you group become          * child shapes of the group shape and are no longer one of the          * items in Page.Shapes.         *          * This function will not recursive into shapes which have a Master.          * This means that shapes which were created by dropPing from stencils          * will have their propertIEs printed but propertIEs of child shapes          * insIDe them will be ignored. I do this because such propertIEs are          * not typically shown to the user and are often used to implement          * features of the shapes such as data graphics.         *          * An alternative halting condition for the recursion which may be          * sensible for many drawing types would be to stop when you          * find a shape with custom propertIEs.         */        public static voID printPropertIEs(Shapes shapes)        {            // Look at each shape in the collection.            foreach (Shape shape in shapes)            {                               // Use this index to look at each row in the propertIEs                 // section.                short iRow = (short) VisRowIndices.visRowFirst;                // While there are stil rows to look at.                while (shape.get_CellsSRCExists(                    (short) VisSectionIndices.visSectionProp,iRow,(short) VisCellindices.visCustPropsValue,(short) 0) != 0)                {                    // Get the label and value of the current property.                    string label = shape.get_CellsSRC(                            (short) VisSectionIndices.visSectionProp,(short) VisCellindices.visCustPropsLabel                        ).get_ResultStr(VisUnitCodes.visNoCast);                    string value = shape.get_CellsSRC(                            (short) VisSectionIndices.visSectionProp,(short) VisCellindices.visCustPropsValue                        ).get_ResultStr(VisUnitCodes.visNoCast);                    // Print the results.                    Console.Writeline(string.Format(                        "Shape={0} Label={1} Value={2}",shape.name,label,value));                    // Move to the next row in the propertIEs section.                    iRow++;                }                // Now look at child shapes in the collection.                if (shape.Master == null && shape.Shapes.Count > 0)                    printPropertIEs(shape.Shapes);            }        }    }}
总结

以上是内存溢出为你收集整理的c# – 如何在Visio中读取Shape的属性全部内容,希望文章能够帮你解决c# – 如何在Visio中读取Shape的属性所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1261225.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存