您的位置:首页 > 编程语言 > ASP

使用 Aspose.Slide 获取PPT中的所有幻灯片的标题

2015-04-20 10:27 253 查看
本文使用的是第三方类库 Aspose.Slide,如果你使用的是OpenXml可以看下面的链接,原理是相同的,这个文章里也有对Xml标签的详细解释。

如何:获取演示文稿中的所有幻灯片的标题

原理:

  原理说白了很简单,明白了原理大家都写得出来。

  简单说,一个PPT里有多个幻灯片,一个幻灯片里有多个Shape, Shape会有一个Plcaeholder,Placeholder的Type属性来决定是否是标题。

  Aspose的对像 IPresentation->Slide->Shape->PlaceHolder

代码:

判断Shape是一个Title,采用了扩展方法的方式:

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;
}
}
}
}


总结:

  这东西本身,很简单的东西,主要就是判断哪个属性。幸好查到了微软的那篇文章。

本文原创

转载请注明出处:/article/7076055.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: