Use Aspose. Slide to obtain the titles of all slides in the PPT,
This article uses a third-party class library Aspose. Slide. If you are using OpenXml, you can see the following link. The principles are the same. This article also provides a detailed explanation of the Xml tag.
How to: Get titles of all slides in a presentation
Principle:
The principle is easy to explain, and everyone can understand the principle.
Simply put, a PPT contains multiple slides, one slide contains multiple shapes, and the Shape has a Plcaeholder. The Type attribute of Placeholder determines whether the title is used.
Aspose IPresentation-> Slide-> Shape-> PlaceHolder
Code:
To determine whether a Shape is a Title, use the extension method:
Public static class ShapeExtension {public static bool IsTitleShape (this IShape p_shape) {if (p_shape = null) {return false;} var placeholder = p_shape.Placeholder; if (placeholder! = Null) {switch (placeholder. type) {// Any title shape. case PlaceholderType. title: // A centered title. case PlaceholderType. centeredTitle: return true; default: return false ;}}View Code
We define a SlideTitle to store.
Public class SlideTitle {public int PageNum {get; set;} public int TitleCount {get; set;} public string [] Titles {get; set ;}}View Code
Expand the IPresentation object and add a GetTitles method.
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; } } } }
Summary:
This is a very simple thing, mainly to determine which attribute. Fortunately, I found Microsoft's article.
Original article
Reprinted please indicate the source: http://www.cnblogs.com/gaoshang212/p/4440807.html