Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Visio中读取形状属性_C#_Visio - Fatal编程技术网

C# 如何在Visio中读取形状属性

C# 如何在Visio中读取形状属性,c#,visio,C#,Visio,我在评论中问到这个代码已经被删除了。 所以我创造了一个新的主题 帮帮我。此代码打开文档。第一页。但是表单上找不到形状!我总是把iRow=0。但是形状在一张纸上!我自己做的​​提前告诉他们!问题出在哪里?我在代码中没有看到任何东西会阻止它在Visio 2007中工作。您需要使用文件路径,该文件在第一页包含具有自定义属性的形状。我建议您删除俄语,因为StackOverflow是一个英语网站,它将吸引向下的投票。您使用的Visio版本是什么?您使用的是随Visio一起安装的文件“ASTMGT_.VST

我在评论中问到这个代码已经被删除了。 所以我创造了一个新的主题


帮帮我。此代码打开文档。第一页。但是表单上找不到形状!我总是把iRow=0。但是形状在一张纸上!我自己做的​​提前告诉他们!问题出在哪里?

我在代码中没有看到任何东西会阻止它在Visio 2007中工作。您需要使用文件路径,该文件在第一页包含具有自定义属性的形状。

我建议您删除俄语,因为StackOverflow是一个英语网站,它将吸引向下的投票。您使用的Visio版本是什么?您使用的是随Visio一起安装的文件“ASTMGT_.VST”还是其他文件?@saveenr:提出问题的人可能没有使用Visio 10。他们可能刚刚从这个答案()复制了代码,并试图让它正常工作。他们问题中的短语“我自己已经预先制作好了”让我觉得他们没有在代码中使用该文件。@PatLeahy-很好!Sinlop,如果您能更具体地了解您使用的Visio版本,这将有所帮助。我尝试了您为Visio 2010提供的代码,它工作正常。抱歉。我正在使用Visio2007。是的。我正在使用这个答案中的代码。很遗憾,我无法使用Visio 10。该代码仅适用于此版本?
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 content\1033\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, 
                            iRow,
                            (short) VisCellIndices.visCustPropsLabel
                        ).get_ResultStr(VisUnitCodes.visNoCast);

                    string value = shape.get_CellsSRC(
                            (short) VisSectionIndices.visSectionProp, 
                            iRow,
                            (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);
            }
        }
    }
}