简体   繁体   English

MS Office openxml 获取PowerPoint幻灯片的幻灯片布局

[英]MS Office openxml get slide layout of powerpoint slide

I'm extracting data from powerpoint documents by reading the underlying xml.我通过阅读底层 xml 从 powerpoint 文档中提取数据。

I want to get the name of the slide master layout that a particular slide is using, but I can't figure out how to get this info from the slide element in question.我想获取特定幻灯片正在使用的幻灯片母版布局的名称,但我不知道如何从相关幻灯片元素中获取此信息。

For example, My slide master has many layouts, and one is called 1_Title Slide .例如,我的幻灯片母版有多种布局,其中一种称为1_Title Slide

I can open the xml and find the list of slide master layouts and names pretty easily.我可以打开 xml 并轻松找到幻灯片母版布局和名称列表。 The slidemaster layout that I want looks like this:我想要的幻灯片母版布局如下所示:

<p:sldLayout xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" showMasterSp="0" userDrawn="1"><p:cSld name="1_Title Slide">... </p:sldLayout>

Where the layut name is clearly 1_Title Slide .布局名称显然是1_Title Slide

However, when I search for that string within the <p:sld /> slide element that I know is using that layout, I cannot find that text.但是,当我在我知道正在使用该布局的<p:sld />幻灯片元素中搜索该字符串时,我找不到该文本。 The layout has a lot of different elements and attributes, presumably because the layout in question has several placeholders and shapes, and so it's not easy to find out how the xml may be referencing it.布局有很多不同的元素和属性,大概是因为有问题的布局有几个占位符和形状,所以很难找出 xml 是如何引用它的。 What tag or attribute in openxml stores the "unique id" of the layout within the slide element? openxml 中的哪些标记或属性将布局的“唯一 ID”存储在幻灯片元素中? How is it mapped?它是如何映射的?

Just so you know, a layout with a title like 1_Title Slide is an accidental layout that got there by pasting in a slide from a different presentation.如您所知,标题为 1_Title Slide 的布局是一种意外布局,它是通过粘贴来自不同演示文稿的幻灯片来实现的。 It's not native to the template or theme.它不是模板或主题所固有的。

For references to relationships among XML parts, look in the _rels folder for the relationship file.有关 XML 部件之间关系的参考,请在_rels文件夹中查找关系文件。 So slide1.xml will have a file in there called slide1.xml.rels .所以slide1.xml将有一个名为slide1.xml.rels的文件。 One of the entries will look something like this:其中一个条目将如下所示:

<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout7.xml"/>

Then open slideLayout7.xml and get the layout name.然后打开 slideLayout7.xml 并获取布局名称。

According to the Microsoft Documentation , Open XML SDK is defined this way:根据Microsoft 文档,Open XML SDK 是这样定义的:

The Open XML SDK 2.5 simplifies the task of manipulating Open XML packages and the underlying Open XML schema elements within a package. The Open XML SDK 2.5 simplifies the task of manipulating Open XML packages and the underlying Open XML schema elements within a package. The Open XML SDK 2.5 encapsulates many common tasks that developers perform on Open XML packages, so that you can perform complex operations with just a few lines of code. Open XML SDK 2.5 封装了开发人员在 Open XML 包上执行的许多常见任务,因此您只需几行代码即可执行复杂的操作。

But it looks like solving your problem with slide layouts with the Open XML SDK is not easy.但看起来用 Open XML SDK 解决您的幻灯片布局问题并不容易。 If you use Aspose.Slides for .NET you will get the slide layout as shown below:如果您将Aspose.Slides 用于 .NET ,您将获得如下所示的幻灯片布局:

using var presentation = new Presentation("example.pptx");
var firstSlide = presentation.Slides[0];
var layoutName = firstSlide.LayoutSlide.Name;

Documentation |文档| API Reference | API 参考| Free forum免费论坛

You can also evaluate Aspose.Slides Cloud for presentation manipulating.您还可以评估Aspose.Slides Cloud以进行演示操作。 This REST-based API allows you to make 150 free API calls per month for API learning and presentation processing.这个基于 REST 的 API 允许您每月为 API 学习和演示处理进行 150 次免费的 API 调用。

I work at Aspose.我在 Aspose 工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM