本文使用的是第三方類庫 Aspose.Slide,如果你使用的是OpenXml可以看下面的鏈接,原理是相同的,這個文章裡也有對Xml標簽的詳細解釋。
如何:獲取演示文稿中的所有幻燈片的標題
原理:
原理說白了很簡單,明白了原理大家都寫得出來。
簡單說,一個PPT裡有多個幻燈片,一個幻燈片裡有多個Shape, Shape會有一個Plcaeholder,Placeholder的Type屬性來決定是否是標題。
Aspose的對像 IPresentation->Slide->Shape->PlaceHolder
代碼:
判斷Shape是一個Title,采用了擴展方法的方式:

我們定義一個SlideTitle來存放

再擴展IPresentation對象,增加一個GetTitles的方法
public static class PresentationExtension
{
public static IEnumerable<SlideTitle> GetTitles(this IPresentation p_presentation)
{
var presentation = p_presentation;
if (presentation != null)
{
foreach (var slide in presentation.Slides)
{
List<string> titles = new List<string>();
foreach (var shape in slide.Shapes)
{
if (!shape.IsTitleShape())
{
continue;
}
var autoShape = shape as AutoShape;
if (autoShape == null)
{
continue;
}
titles.Add(autoShape.TextFrame.Text);
}
var title = new SlideTitle()
{
PageNum = slide.SlideNumber,
TitleCount = titles.Count,
Titles = titles.ToArray()
};
yield return title;
}
}
}
}
總結:
這東西本身,很簡單的東西,主要就是判斷哪個屬性。幸好查到了微軟的那篇文章。
本文原創
轉載請注明出處:http://www.cnblogs.com/gaoshang212/p/4440807.html