none
Slide vs. SlideLayout - which to update Programmatically? RRS feed

  • Question

  • Hello,

    If I'm using a slide template that consists of a basic Master Page and a SlideLayout, then what I'd like to know is:

    When I'm updating the PowerPoint presentation programmatically, which object should I focus on updating - the SlidePart or the SlideLayoutPart?  One question I have is how do you update a SlideLayout, then merge the SlideLayout into a Slide such that the final product, to the end user, is just a slide with the correct data and nothing else?

    Thanks.

    Wednesday, February 23, 2011 5:07 PM

Answers

  • Well, I think I know what my problem was, it was with how PowerPoint handles the whole Layout thing.  I had thought that a Layout could be "permanently" applied to a slide, such that the slide had the data/items transferred/stamped to it.  Turns out a Layout remains separate from the slide; it shows up okay in a full screeen/briefing mode, etc. but not in normal mode, it appears like two separate files, which they are.  So instead, I'm not using a Layout but using a basic master for static content common to all the slides, and then using a plain Slide as a template. 
    • Marked as answer by sdfsda Monday, March 14, 2011 5:05 PM
    Monday, March 14, 2011 5:05 PM
  • Hi,

    You can create the template manually. Template can consist of Slide Masters and Slide Layouts. You can also have a slide as part of the template which you can copy to create the new slides.

    Then programmatically, you can add slides to the template and apply layout to the slide. A Slide Layout is directly linked to a Slide Master.

    You can refer to the following link for Working with Slide Layouts

    http://msdn.microsoft.com/en-us/library/gg278311.aspx

    To work with Slides you may refer to http://msdn.microsoft.com/en-us/library/dd469465(v=office.12).aspx#CreateDocswithOpenXMLSDK_CreatingaPresentationReportBasedonData .

    Let me know if this helps.

    Thanks

    Pradip

     

    • Proposed as answer by Bruce Song Thursday, March 10, 2011 2:29 AM
    • Marked as answer by sdfsda Monday, March 14, 2011 5:05 PM
    Wednesday, March 2, 2011 10:21 PM

All replies

  • Okay, so an update - I'm glad I submitted this because I've found that I can't update a Slide Layout via XmlDocument, but I can an actual Slide.  This is kind of a pain if I have to use a SlideLayout as a template for producing new slides.  Here's the code I use to update a SlidePart - this works:

    SlidePart slidePart = (SlidePart)presentationPart.GetPartById("rId2");
    XmlDocument xmldoc = new xmlDocument(nametable);
    xmldoc.Load(slidePart.GetStream());
    string searchString = "//p:spTree/p:sp/p:txBody/a:p/a:r/a:t");
    
    XmlNodeList xNodes = xmldoc.SelectNodes(searchString, nsManager);
    
    foreach (XmlNode xNode in xNodes)
    {
      if (xNode.InnerText == "[Some Text]")
        xNode.InnterText = "[Some New Text]";
      xmldoc.Save(slidePart.GetStream());
    }
    

    However, below is the code I'm trying for a SlideLayoutPart, which does not work:

    SlideMasterPart master = (SlideMasterPart)presentationPart.GetPartById("rId1");
    
    SlideLayoutPart layout = (SlideLayoutPart)master.GetPartById("rId1");
    
    SlideLayout sldLayout = layout.SlideLayout;
    
    IEnumerable<DocumentFormat.OpenXml.Drawing.TextBody> txtBodies = sldLayout.Descendents<DocumentFormat.OpenXml.Drawing.TextBody>();
    
    foreach (DocumentFormat.OpenXml.Drawing.TextBody txtBody in txtBodies)
    {
      if (txtBody.InnerText == "[Some Text]")
        txtBody.InnerText.Replace("[Some Text]", "Some New Text");
      sldLayout.Save();
    }

    So, how would I find items of text (Placehoders, etc.) inside a Layout and update/save them such that they show up in a final Slide output?

    Thanks.

    Wednesday, February 23, 2011 10:33 PM
  • Hi Sdfsda,

    Thanks for posting. I am trying to involve someone who is familiar with this problem. So, there might be some delay. Appreciate your patience. Thank you for your understanding and support.

    Best Regards,

     


    Bruce Song [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.

    Thursday, February 24, 2011 8:30 AM
  • Hi,

    You can create the template manually. Template can consist of Slide Masters and Slide Layouts. You can also have a slide as part of the template which you can copy to create the new slides.

    Then programmatically, you can add slides to the template and apply layout to the slide. A Slide Layout is directly linked to a Slide Master.

    You can refer to the following link for Working with Slide Layouts

    http://msdn.microsoft.com/en-us/library/gg278311.aspx

    To work with Slides you may refer to http://msdn.microsoft.com/en-us/library/dd469465(v=office.12).aspx#CreateDocswithOpenXMLSDK_CreatingaPresentationReportBasedonData .

    Let me know if this helps.

    Thanks

    Pradip

     

    • Proposed as answer by Bruce Song Thursday, March 10, 2011 2:29 AM
    • Marked as answer by sdfsda Monday, March 14, 2011 5:05 PM
    Wednesday, March 2, 2011 10:21 PM
  • Well, I think I know what my problem was, it was with how PowerPoint handles the whole Layout thing.  I had thought that a Layout could be "permanently" applied to a slide, such that the slide had the data/items transferred/stamped to it.  Turns out a Layout remains separate from the slide; it shows up okay in a full screeen/briefing mode, etc. but not in normal mode, it appears like two separate files, which they are.  So instead, I'm not using a Layout but using a basic master for static content common to all the slides, and then using a plain Slide as a template. 
    • Marked as answer by sdfsda Monday, March 14, 2011 5:05 PM
    Monday, March 14, 2011 5:05 PM