Use Aspose. Slide to obtain the titles of all slides in the PPT,

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.