none
How read slide master's shapes which are deployed on slide?

    Question

  • Sorry for my English :)

    I try to read  the X and Y coordinate of the shapes of the first slide

    using DocumentFormat.OpenXml.Packaging;
    using P = DocumentFormat.OpenXml.Presentation;
    
    namespace OpenXmlApp
    {
        public class ShapeReader
        {
            public static void ReadSlideShapes(string presentationPath)
            {
                using (var doc = PresentationDocument.Open(presentationPath, false))
                {                
                    var shapes = doc.PresentationPart.SlideParts.First().Slide.Descendants<P.Shape>();
                    foreach (var shape in shapes)
                    {
                        var tr = shape.ShapeProperties.Transform2D;
                        if (tr != null)
                        {
                            Debug.WriteLine($"X: {tr.Offset.X}, Y: {tr.Offset.Y}");
                        }
                    }
                }
            }
        }
    }
    but Transform2D is not access for the shapes which on the slide master (tr == null).

    Yes, of course I can read slide master's shapes so:

    public static void ReadSlideMasterShapes(string presentationPath)
    {
        using (var doc = PresentationDocument.Open(presentationPath, false))
        {
            var shapes = doc.PresentationPart.SlideParts.First()
                                                        .SlideLayoutPart.SlideMasterPart.SlideMaster
                                                        .Descendants<P.Shape>();
            foreach (var shape in shapes)
            {
                var tr = shape.ShapeProperties.Transform2D;
                if (tr != null)
                {
                    Debug.WriteLine($"X: {tr.Offset.X}, Y: {tr.Offset.Y}");
                }
            }
        }
    }
    but then the slide master's shapes are always read even some shape is not used. How I can read slide master's shape which are deployed on slide?


    lundi 16 avril 2018 20:01

Toutes les réponses

  • Hello adamShakhabov,

    I'm wondering how do you make a shape in slide master not used in slide? In my test, all shapes in slide master will be set to slide. To be honestly, I'm not very familiar with PPT products function. Would you mind detail us how could we reproduce your issue? 

    By the way, what's the state of below thread? Has your issue been resolved? If it, I would suggest you mark helpful reply or share your solution and mark it to close the thread. If not, please feel free to follow up to let us know your issue.

    System.IO.IOException: 'The process cannot access the file 'x' because it is being used by another process.'

    Thanks for understanding.

    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.


    mardi 17 avril 2018 02:07
    Modérateur
  • Each slide has at least one slide master with its own shapes. When using PowerPoint, user removes a shape from slide, we also have the ability to remove the shape from slide master. However, Open XML SDK continuous to read all shapes from slide master, including the removed shapes.

    mercredi 18 avril 2018 13:16
  • Hello adamShakhbov,

    What's the version of your office? Which shape did you use? Would you mind share a simply ppt file which deletes a slide master shape from a slide? 

    Besides the default text boxes shapes, I failed to edit any other shapes. Did I misunderstand any thing?

    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.

    jeudi 19 avril 2018 05:35
    Modérateur