none
How get shape's type RRS feed

  • Question

  • Sorry my English :)

    Tell me please how I can get shape's type in Open XML. If it is not hard to get coordinates

    Slide firstSlide = doc.PresentationPart.SlideParts.First().Slide;
    CommonSlideData csd = firstSlide.GetFirstChild<CommonSlideData>();
    var shapes = csd.Descendants<Shape>();
    
    foreach (var shape in shapes)
    {                                                          
        var t2d = shape.ShapeProperties.Transform2D;
        if (t2d != null)
        {
            Console.WriteLine($"X: {t2d.Offset.X}\nY: {t2d.Offset.Y}");
        }
    }

    but where store type? For example, in Interop.PowerPoint each shape object has property Type which store value with prefix mso*.




    • Edited by adamShakhabov Saturday, March 10, 2018 2:26 PM change errors
    Saturday, March 10, 2018 2:19 PM

Answers

  • Hello adamShakhabov,

    I would suggest you get the PresetGeometry property and then use the get value to compare with below enumeration list to get know what's the shape.

    http://www.datypic.com/sc/ooxml/t-a_ST_ShapeType.html

    Here is the simply code.

     Slide firstSlide = doc.PresentationPart.SlideParts.First().Slide;
                    CommonSlideData csd = firstSlide.GetFirstChild<CommonSlideData>();
                    var shapes = csd.Descendants<Shape>();
    
                    foreach (Shape shape in shapes)
                    {
                        A.PresetGeometry prst = shape.ShapeProperties.GetFirstChild<A.PresetGeometry>();
                        if (prst != null)
                        {
                            Console.WriteLine(prst.Preset);
                        }
                    }

    Best Regards,

    Terry

    Disclaimer: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 12, 2018 2:05 AM

All replies

  • Hello adamShakhabov,

    I would suggest you get the PresetGeometry property and then use the get value to compare with below enumeration list to get know what's the shape.

    http://www.datypic.com/sc/ooxml/t-a_ST_ShapeType.html

    Here is the simply code.

     Slide firstSlide = doc.PresentationPart.SlideParts.First().Slide;
                    CommonSlideData csd = firstSlide.GetFirstChild<CommonSlideData>();
                    var shapes = csd.Descendants<Shape>();
    
                    foreach (Shape shape in shapes)
                    {
                        A.PresetGeometry prst = shape.ShapeProperties.GetFirstChild<A.PresetGeometry>();
                        if (prst != null)
                        {
                            Console.WriteLine(prst.Preset);
                        }
                    }

    Best Regards,

    Terry

    Disclaimer: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 12, 2018 2:05 AM
  • Hello adamShakhabov,

    Has your original issue been resolved? If it has, I would suggest you mark the helpful reply as answer or provide your solution and mark as answer to close this thread. If not, please feel free to let us know your current issue.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 13, 2018 5:18 AM
  • How may I convert PresetGeometry (Open XML SDK) into MsoShapeType (Microsoft.Office.Core)?

     

    Tuesday, March 13, 2018 9:08 PM