locked
How to fill _any_ placeholder in a PowerPoint programatically? RRS feed

  • Question

  • Hi,

    There has been already a question regarding this, but the solution for that is not working 100% and I really need your help.

    This was the original thread:
    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/3f5f5620-9992-45af-828b-6fd49f3ec6a6

    The question was how to place a picture into a placeholder in PowerPoint with CSharp code. The provided solution was this:

    PowerPoint.Shape shape = PPSlide3.Shapes[1];
    PPSlide3.Shapes.AddPicture(@"C:\Temp\2.jpg" ,
    Microsoft.Office.Core.MsoTriState.msoTrue,
    Microsoft.Office.Core.MsoTriState.msoTrue,
    shape.Left, shape.Top, shape.Width, shape.Height);

    BUT the code works only for the first placeholder (when index is 1). If I change the index to 2 or greater (e.g. PPSlide3.Shapes[2]), the picture is still inserted into the first placeholder.

    I made a workaround by selecting the placeholder and copy-pasting the picture into it programatically, but this needs an open (visible) PowerPoint window (for the placeholder selection), which is really not OK for our customer.

    My question is: Is there a possibility to fill in every placeholder in the document programatically without visible windows?

    Thank you in advance.

    Friday, December 17, 2010 8:13 AM

Answers

All replies

  • Hello T.Peter,

    Thanks for posting. I will do some research on this issue. Absolutely, I will follow up if I have some useful information shared with you. Have a nice day.


    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, December 20, 2010 12:13 PM
  • Hello again,

    When you change the index to 2, is this shape also shape (PowerPoint.Shape) defined above? Have you changed the name? I made some changes on my side to add two picture. However, I am not able to reproduce this issue. Thanks.

    Code like this,

                try
                {
                    PowerPoint.Presentation presentation = Globals.ThisAddIn.Application.ActivePresentation;
                    PowerPoint.Slide slide1 = presentation.Slides[2];
                    foreach (PowerPoint.Shape shape in slide1.Shapes)
                    {
                        //if (shape.Type == Office.MsoShapeType.msoPlaceholder)
                        //{
                            slide1.Shapes.AddPicture(@"C:\Temp\1.bmp", Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Top, shape.Left, shape.Width, shape.Height);                        
                        //}
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

    Please check if there is a difference between us. Just feel free to follow up, if you have any concern on this post. Have a nice day.


    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, December 21, 2010 9:27 AM
  • Hi,

    The problem is, that I do not want to fill every placeholder or shape on the slide, just for example the 2nd placeholder. But when I use the 2nd placeholder shape for positioning the new picture, the picture is still inserted to the first placeholder:

     

    PowerPoint.Shape shape = PPSlide.Shapes.Placeholders[2];

    PPSlide.Shapes.AddPicture(@"C:\Temp\2.jpg" ,
      Microsoft.Office.Core.MsoTriState.msoFalse,
      Microsoft.Office.Core.MsoTriState.msoTrue,
      shape.Left, shape.Top, shape.Width, shape.Height);

     

    I use the Slide.Shapes.Placeholders collection to access the placeholder shape object (but I think this object is the same as the corresponding entry in the Slide.Shapes). But this should not be a problem, because I use only the position information from this shape object.

    Thanks,
    Peter

    Tuesday, December 21, 2010 9:51 AM
  • Hi Peter

    As far as I can tell, this isn't something that's supported. At least, not directly. See

    http://www.tech-archive.net/Archive/Office/microsoft.public.powerpoint/2009-10/msg01098.html

    and

    http://www.pptfaq.com/FAQ00352.htm

    I recommend you take this to the specialized PowerPoint forum on Answers, as that's where you'll find the application specialists, including the programmers. If anyone can help you further with this, it will be they

    http://answers.microsoft.com/en-us/default.aspx


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Bessie Zhao Friday, December 24, 2010 12:03 PM
    • Marked as answer by Bessie Zhao Monday, December 27, 2010 7:18 AM
    Thursday, December 23, 2010 9:35 AM