Question

I'm trying to analyze an existing PowerPoint 2010 .pptx file using the OpenXML SDK 2.0.

What I'm trying to achieve is to

  • enumerate the slides in order (as they appear in the PPTX)
  • extracting all textual bits from each slide

I've started and gotten so far - I can enumerate the SlideParts from the PresentationPart - but I cannot seem to find a way to make this an ordered enumeration - the slides are being returned in pretty much arbitrary order...

Any trick to get these slides in the order defined in the PPTX file?

using (PresentationDocument doc = PresentationDocument.Open(fileName, false))
{
   // Get the presentation part of the document.
   PresentationPart presentationPart = doc.PresentationPart;

   foreach (var slide in presentationPart.SlideParts)
   {
        ...
   }
}

I was hoping to find something like a SlideID or Sequence number or something - some item or property I could use in a Linq expression like

.OrderBy(s => s.SlideID)

on that slideparts collection.

Was it helpful?

Solution

It's a bit more involved than I had hoped for - and the docs are a bit sketchy at times....

Basically, I had to enumerate the SlideIdList on the PresentationPart and do some XML-foo to get from that SlideId to the actual slide in the OpenXML presentation.

Something along the lines of:

using (PresentationDocument doc = PresentationDocument.Open(fileName, false))
{
    // Get the presentation part of the document.
    PresentationPart presentationPart = doc.PresentationPart;

    // get the SlideIdList
    var items = presentationPart.Presentation.SlideIdList;

    // enumerate over that list
    foreach (SlideId item in items)
    {
        // get the "Part" by its "RelationshipId"
        var part = presentationPart.GetPartById(item.RelationshipId);

        // this part is really a "SlidePart" and from there, we can get at the actual "Slide"
        var slide = (part as SlidePart).Slide;

        // do more stuff with your slides here!
    }
}

OTHER TIPS

The closest I found was this snippet:

[ISO/IEC 29500-1 1st Edition]

sld (Presentation Slide)

This element specifies a slide within a slide list. The slide list is used to specify an ordering of slides.

[Example: Consider the following custom show with an ordering of slides.

<p:custShowLst>
  <p:custShow name="Custom Show 1" id="0">
    <p:sldLst>
      <p:sld r:id="rId4"/>
      <p:sld r:id="rId3"/>
      <p:sld r:id="rId2"/>
      <p:sld r:id="rId5"/>
    </p:sldLst>
  </p:custShow>
</p:custShowLst>In the above example the order specified to present the slides is slide 4, then 3, 2 and finally 5. end example]

In the MSDN documentation for the slide class

It seems that slides have an r:id of the form rId## where ## is the number of the slide. Maybe that's enough to get you going again?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top