none
Getting the relationship ID of a shape via looking for their names (PowerPoint) RRS feed

  • Question

  • Hey there,

    how can I get the relationship ID of a shape through their name? What I want to do is something like this:

    	public static String GetShapeRId (Slide slide, String name)
    	{
    		foreach (Shape shape in shapes)
    		{
    			if (shape.NonVisualShapeProperties.NonVisualDrawingProperties.Name == name)
    			{
    				return shape.RelationshipID; // This is the part I am looking for.
    			}
    		}
    		return null;
    	}
    I am quite new to C# and OpenXML so as always suggestions for code improvements would be appreciated as well.
    Friday, August 5, 2016 8:18 AM

Answers

  • Hi,

    What do you mean the relationship ID of shapes?

    Is it the id value of a shape as shown below?

     

      <p:nvSpPr>

        <p:cNvPr id="3" name="Content Placeholder 2" />

        <p:cNvSpPr>

          <a:spLocks noGrp="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" />

        </p:cNvSpPr>

        <p:nvPr>

          <p:ph idx="1" />

        </p:nvPr>

      </p:nvSpPr>

     

    Use:

    return shape.NonVisualShapeProperties.NonVisualDrawingProperties.Id

     

    E.g.

     string docName = (@"C:\Users\Administrator\Desktop\Presentation1.pptx");
                using (PresentationDocument ppt = PresentationDocument.Open(docName, false))
                {
                    PresentationPart pptPart = ppt.PresentationPart;
                    foreach (SlidePart slide in pptPart.SlideParts)
                    {
                        ShapeTree shapes = slide.Slide.CommonSlideData.ShapeTree;
                        foreach (Shape shape in shapes.Elements<Shape>())
                        {
                            if (shape.NonVisualShapeProperties.NonVisualDrawingProperties.Name == "Content Placeholder 2")
                            {
                                Console.WriteLine(shape.NonVisualShapeProperties.NonVisualDrawingProperties.Id.ToString());
                                Console.ReadLine();
                            }
                        }
                    }
                }
    

    Monday, August 8, 2016 5:51 AM
    Moderator