简体   繁体   中英

MS Office openxml get slide layout of powerpoint slide

I'm extracting data from powerpoint documents by reading the underlying xml.

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 .

I can open the xml and find the list of slide master layouts and names pretty easily. 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 .

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. 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. What tag or attribute in openxml stores the "unique id" of the layout within the slide element? 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. 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. So slide1.xml will have a file in there called 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.

According to the Microsoft Documentation , Open XML SDK is defined this way:

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.

But it looks like solving your problem with slide layouts with the Open XML SDK is not easy. If you use Aspose.Slides for .NET you will get the slide layout as shown below:

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

Documentation | API Reference | Free forum

You can also evaluate Aspose.Slides Cloud for presentation manipulating. This REST-based API allows you to make 150 free API calls per month for API learning and presentation processing.

I work at Aspose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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