Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Thu Jun 23, 2022 5:13 pm

I would like to get a specific shape on my slide, however there are multiple shapes with the same name. What is your recommendation on how to get the one I want.

I want to get the picture with the bmw car.

duplicate names.PNG


Couple of notes - I cannot manually change the names of the shapes. I'm guessing the only way is to find duplicate names and programmatically change the names?

Here's the same code I currently use.

Code: Select all
Presentation PPT = new Presentation();
PPT.LoadFromFile("Input.pptx");
foreach (IShape s in PPT.Slides[0].Shapes)
{
    if (s is SlidePicture)
    {
        SlidePicture ps = s as SlidePicture;
        if (ps.Name == "Picture 4")
        {
            //...
        }
    }
}
PPT.SaveToFile("output.pptx", Spire.Presentation.FileFormat.Pptx2013);

majeed_s
 
Posts: 80
Joined: Thu Mar 25, 2021 4:13 pm

Fri Jun 24, 2022 9:36 am

Hi,

Thank you for your inquiry.
We provide two properties (AlternativeTitle and AlternativeText) to get the title and alttext of shape, you can manually set the values for the specific shape you want (I attached a screenshot for your reference), and use the code below to distinguish it from other shapes.
Code: Select all
 
            //Load a PPT
            Presentation PPT = new Presentation();
            PPT.LoadFromFile("Input.pptx");
            ShapeCollection shapes = PPT.Slides[0].Shapes;
            foreach (IShape s in PPT.Slides[0].Shapes)
            {
                //Get shape by alttext
                // if (s.AlternativeText == "carInfo")
                //Get shape by title
                if (s.AlternativeTitle == "carTitle")
               {
                 //...
               }
            }

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Fri Jun 24, 2022 1:41 pm

Perfect. Thanks for highlighting this.

majeed_s
 
Posts: 80
Joined: Thu Mar 25, 2021 4:13 pm

Mon Jun 27, 2022 9:47 am

Hi,

If you need assistance in the future, please don't hesitate to contact us.
Wish you a nice day!

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Return to Spire.Presentation