3

.pptx我正在尝试使用 OpenXML SDK 2.0分析现有的 PowerPoint 2010文件。

我想要实现的是

  • 按顺序枚举幻灯片(因为它们出现在 PPTX 中)
  • 从每张幻灯片中提取所有文本位

我已经开始并且到目前为止 - 我可以枚举SlideParts来自PresentationPart- 但我似乎无法找到一种方法来使其成为有序枚举 - 幻灯片以几乎任意顺序返回......

有什么技巧可以按照 PPTX 文件中定义的顺序获取这些幻灯片吗?

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

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

我希望找到一个SlideIDSequence数字之类的东西——我可以在 Linq 表达式中使用的一些项目或属性,比如

.OrderBy(s => s.SlideID)

在那个幻灯片集合上。

4

2 回答 2

6

它比我希望的要复杂一些——而且文档有时有点粗略......

基本上,我必须枚举SlideIdListPresentationPart做一些 XML-foo 以从它SlideId到 OpenXML 演示文稿中的实际幻灯片。

类似于以下内容:

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!
    }
}
于 2013-02-20T18:07:38.023 回答
2

我找到的最接近的是这个片段:

[ISO/IEC 29500-1 第 1 版]

sld(演示幻灯片)

此元素指定幻灯片列表中的一张幻灯片。幻灯片列表用于指定幻灯片的顺序。

[示例:考虑以下带有幻灯片排序的自定义节目。

<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]

该类的MSDN 文档中slide

幻灯片似乎有一个 r:id 的形式rId##,其中 ## 是幻灯片的编号。也许这足以让你再次出发?

于 2013-02-19T22:29:01.327 回答