2013-04-12 2 views
1
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); 
      } 
     } 
    } 
} 

이 코드에 주석에서 물어 본 것은 제거되었습니다. 그래서 새로운 테마를 만들었습니다.Visio에서 셰이프 속성을 읽는 방법

도와주세요. 이 코드는 문서를 엽니 다. 첫 번째 페이지. 그러나! 모양 시트에서 찾을 수 없습니다! 난 항상 iRow = 0.하지만! 모양이 시트에 있습니다! 나는 나 자신을 미리 만들었다! 무엇이 문제일까요?

+0

러시아어를 제거하는 것이 좋습니다. StackOverflow는 영어 언어 사이트이기 때문에 다운 투표를 할 것입니다. – Joe

+0

어떤 버전의 Visio를 사용하고 있습니까? Visio 또는 다른 파일과 함께 설치된 "ASTMGT_U.VST"파일을 사용하고 있습니까? –

+0

@saveenr : 질문을 한 사람이 Visio 10을 사용하고 있지 않을 수 있습니다.이 대답 (http://stackoverflow.com/a/6274758/9182)에서 코드를 복사하고 작동 시키려고 시도했을 수 있습니다. "나는 나 자신을 사전에 만들었다."라는 문구는 그들이 코드에서 파일을 사용하지 않는다고 생각하게 만듭니다. –

답변

0

Visio 2007에서 작업하지 못하게하는 코드에는 아무것도 표시되지 않습니다. 사용자 지정 속성이있는 첫 페이지의 셰이프가 포함 된 파일의 경로를 사용해야합니다.

관련 문제