国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

使用 Aspose.Slide 獲取PPT中的所有幻燈片的標題

2019-11-17 02:26:16
字體:
來源:轉載
供稿:網友

使用 aspose.Slide 獲取PPT中的所有幻燈片的標題

本文使用的是第三方類庫 Aspose.Slide,如果你使用的是Openxml可以看下面的鏈接,原理是相同的,這個文章里也有對Xml標簽的詳細解釋。

如何:獲取演示文稿中的所有幻燈片的標題

原理:

  原理說白了很簡單,明白了原理大家都寫得出來。

  簡單說,一個PPT里有多個幻燈片,一個幻燈片里有多個Shape, Shape會有一個Plcaeholder,Placeholder的Type屬性來決定是否是標題。

  Aspose的對像ipresentation->Slide->Shape->PlaceHolder

代碼:

判斷Shape是一個Title,采用了擴展方法的方式:

    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;                }            }            return false;        }    }
View Code

我們定義一個SlideTitle來存放

    public class SlideTitle    {        public int PageNum { get; set; }        public int TitleCount { get; set; }        public string[] Titles { get; set; }    }
View Code

再擴展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.survivalescaperooms.com/gaoshang212/p/4440807.html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 辽阳市| 四川省| 富民县| 衡水市| 广德县| 民县| 沈阳市| 富顺县| 杭锦旗| 新野县| 朝阳区| 松原市| 安仁县| 桑日县| 甘肃省| 元朗区| 环江| 宁武县| 兰考县| 盐城市| 涿州市| 高雄县| 泽普县| 分宜县| 鹿邑县| 达拉特旗| 司法| 运城市| 新密市| 黄冈市| 瑞金市| 隆化县| 万州区| 泰州市| 竹北市| 宣汉县| 饶阳县| 深泽县| 贵港市| 富川| 镇宁|