使用讲义母版幻灯片
上次修改时间: 2010年10月8日
适用范围: Excel 2010 | Office 2010 | PowerPoint 2010 | Word 2010
本文内容
PresentationML 中的讲义母版幻灯片
Open XML SDK 2.0 HandoutMaster 类
处理 HandoutMaster 类
Open XML SDK 代码示例
生成的 PresentationML
本主题讨论 Open XML SDK 2.0 HandoutMaster 类以及它与 Open XML 文件格式 PresentationML 架构的关系。有关构成 PresentationML 文档的部件和元素的整体结构的详细信息,请参阅 PresentationML 文档的结构。
PresentationML 中的讲义母版幻灯片
ISO/IEC 29500(该链接可能指向英文页面) 规范介绍了 Open XML PresentationML <handoutMaster> 元素,该元素用于表示 PresentationML 文档中的讲义母版幻灯片,如下所示:
此元素指定讲义母版幻灯片的实例。在讲义母版幻灯片中,包含描述讲义幻灯片中的对象及其对应格式的所有元素。在讲义母版幻灯片中, cSld 元素指定共用幻灯片元素,如形状及其附加的文本正文。讲义母版幻灯片中还有其他属性,但 cSld 包含 handoutMaster 幻灯片的大部分预期用途。
© ISO/IEC29500: 2008。
下表列出了 <handoutMaster> 元素的子元素,在处理讲义母版幻灯片及其对应的 Open XML SDK 2.0 类时,会使用该元素。
PresentationML 元素 |
Open XML SDK 2.0 类 |
---|---|
<clrMap> |
|
<cSld> |
|
<extLst> |
|
<hf> |
Open XML SDK 2.0 HandoutMaster 类
Open XML SDK 2.0 HandoutMaster 类表示在 PresentationML 文档的 Open XML 文件格式架构中定义的 <handoutMaster> 元素。使用 HandoutMaster 类可以处理 PresentationML 文档中的各个 <handoutMaster> 元素。
通常与 HandoutMaster 类相关联的类在以下各节中说明。
ColorMap 类
ColorMap 类对应于 <clrMap> 元素。ISO/IEC 29500(该链接可能指向英文页面) 规范中的以下信息介绍了 <clrMap> 元素:
此元素指定可将一种配色方案变换为另一种配色方案的映射层。每个属性表示一个可在此母版中引用的颜色名称,值为主题中的对应颜色。
[示例:请考虑应用于幻灯片母版的以下颜色映射:
<p:clrMap bg1="dk1" tx1="lt1" bg2="dk2" tx2="lt2" accent1="accent1"
accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5"
accent6="accent6" hlink="hlink" folHlink="folHlink"/>
示例结束]
© ISO/IEC29500: 2008。
CommonSlideData 类
CommonSlideData 类对应于 <cSld> 元素。ISO/IEC 29500(该链接可能指向英文页面) 规范中的以下信息介绍了 <cSld> 元素:
此元素指定与所有幻灯片类型相关的幻灯片信息类型的容器。所有幻灯片都共享一组独立于幻灯片类型的通用属性;任何特定幻灯片的这些属性的描述都存储在该幻灯片的 <cSld> 容器中。由父元素指明的特定于幻灯片类型的幻灯片数据存储在其他位置。
<cSld> 中的实际数据只描述特定的父幻灯片;这些数据只是存储的对所有幻灯片通用的信息类型。
© ISO/IEC29500: 2008。
ExtensionListWithModification 类
ExtensionListWithModification 类对应于 <extLst>元素。ISO/IEC 29500(该链接可能指向英文页面) 规范中的以下信息介绍了 <extLst> 元素:
此元素指定具有修改功能的扩展名列表,其中定义了元素类型 <ext> 未来的所有扩展名。扩展名列表以及相应的未来扩展名用于扩展 PresentationML 框架的存储功能,从而允许各种新的数据类型以固有的方式存储在该框架内。
[注意:使用此 extLst 元素,生成应用程序可以存储有关此扩展属性是否已修改的相关信息。注释结束]
© ISO/IEC29500: 2008。
HeaderFooter 类
HeaderFooter 类对应于 <hf> 元素。ISO/IEC 29500(该链接可能指向英文页面) 规范中的以下信息介绍了 <hf> 元素:
此元素指定幻灯片的页眉和页脚信息。页眉和页脚由文本占位符组成,它们在所有幻灯片和幻灯片类型中应该保持一致,例如日期和时间、幻灯片编号以及自定义页眉和页脚文本。
© ISO/IEC29500: 2008。
处理 HandoutMaster 类
如下面的 Open XML SDK 代码示例所示,每个 HandoutMaster 类实例与一个 HandoutMasterPart 类实例相关联,后者表示讲义母版部件,它是 PresentationML 演示文稿文件包的部件之一,也是包含讲义的演示文稿文件所需的部件。
因此,表示 <handoutMaster> 元素的 HandoutMaster 类还与表示 <handoutMaster> 元素的子元素的一系列其他类相关联。这些类包括 CommonSlideData 类、ColorMap 类、ShapeTree 类和 Shape 类,如下面的代码示例所示。
Open XML SDK 代码示例
下面的方法向现有演示文稿中添加一个新讲义母版部件并在这一新的讲义母版部件中创建 Open XML SDK 2.0 HandoutMaster 类的实例。HandoutMaster 类构造函数创建 CommonSlideData 类和 ColorMap 类的实例。CommonSlideData 类构造函数创建 ShapeTree 类的实例,该类的构造函数又创建其他类实例:NonVisualGroupShapeProperties 类的实例、GroupShapeProperties 类的实例以及 Shape 类的实例。
代码中由字母 P 表示的命名空间为 DocumentFormat.OpenXml.Presentation 命名空间。
private static HandoutMasterPart CreateHandoutMasterPart(PresentationPart presentationPart)
{
HandoutMasterPart handoutMasterPart1 = presentationPart.AddNewPart<HandoutMasterPart>("rId3");
handoutMasterPart1.HandoutMaster = new HandoutMaster(
new CommonSlideData(
new ShapeTree(
new P.NonVisualGroupShapeProperties(
new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
new P.NonVisualGroupShapeDrawingProperties(),
new ApplicationNonVisualDrawingProperties()),
new GroupShapeProperties(new TransformGroup()),
new P.Shape(
new P.NonVisualShapeProperties(
new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title 1" },
new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }),
new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
new P.ShapeProperties(),
new P.TextBody(
new BodyProperties(),
new ListStyle(),
new Paragraph(new EndParagraphRunProperties() { Language = "en-US" }))))),
new P.ColorMap() { Background1 = D.ColorSchemeIndexValues.Light1,
Text1 = D.ColorSchemeIndexValues.Dark1,
Background2 = D.ColorSchemeIndexValues.Light2,
Text2 = D.ColorSchemeIndexValues.Dark2,
Accent1 = D.ColorSchemeIndexValues.Accent1,
Accent2 = D.ColorSchemeIndexValues.Accent2,
Accent3 = D.ColorSchemeIndexValues.Accent3,
Accent4 = D.ColorSchemeIndexValues.Accent4,
Accent5 = D.ColorSchemeIndexValues.Accent5,
Accent6 = D.ColorSchemeIndexValues.Accent6,
Hyperlink = D.ColorSchemeIndexValues.Hyperlink,
FollowedHyperlink = D.ColorSchemeIndexValues.FollowedHyperlink });
return handoutMasterPart1;
}
Private Shared Function CreateHandoutMasterPart(ByVal presentationPart As PresentationPart) As HandoutMasterPart
Dim handoutMasterPart1 As HandoutMasterPart = presentationPart.AddNewPart(Of HandoutMasterPart)("rId3")
handoutMasterPart1.HandoutMaster = New HandoutMaster(New CommonSlideData(New ShapeTree(New _
P.NonVisualGroupShapeProperties(New P.NonVisualDrawingProperties() With { _
.Id = DirectCast(1UI, UInt32Value), _
.Name = "" _
}, New P.NonVisualGroupShapeDrawingProperties(), New ApplicationNonVisualDrawingProperties()), New _
GroupShapeProperties(New TransformGroup()), New P.Shape(New P.NonVisualShapeProperties(New P.NonVisualDrawingProperties() With { _
.Id = DirectCast(2UI, UInt32Value), _
.Name = "Title 1" _
}, New P.NonVisualShapeDrawingProperties(New ShapeLocks() With { _
.NoGrouping = True _
}), New ApplicationNonVisualDrawingProperties(New PlaceholderShape())), New P.ShapeProperties(), New _
P.TextBody(New BodyProperties(), New ListStyle(), New Paragraph(New EndParagraphRunProperties() With { _
.Language = "en-US" _
}))))), New P.ColorMap() With { _
.Background1 = D.ColorSchemeIndexValues.Light1, _
.Text1 = D.ColorSchemeIndexValues.Dark1, _
.Background2 = D.ColorSchemeIndexValues.Light2, _
.Text2 = D.ColorSchemeIndexValues.Dark2, _
.Accent1 = D.ColorSchemeIndexValues.Accent1, _
.Accent2 = D.ColorSchemeIndexValues.Accent2, _
.Accent3 = D.ColorSchemeIndexValues.Accent3, _
.Accent4 = D.ColorSchemeIndexValues.Accent4, _
.Accent5 = D.ColorSchemeIndexValues.Accent5, _
.Accent6 = D.ColorSchemeIndexValues.Accent6, _
.Hyperlink = D.ColorSchemeIndexValues.Hyperlink, _
.FollowedHyperlink = D.ColorSchemeIndexValues.FollowedHyperlink _
})
Return handoutMasterPart1
End Function
生成的 PresentationML
Open XML SDK 2.0 代码运行时,以下 XML 会写入代码中引用的 PresentationML 文档。
<?xml version="1.0" encoding="utf-8"?>
<p:handoutMaster xmlns:p="https://schemas.openxmlformats.org/presentationml/2006/main">
<p:cSld>
<p:spTree>
<p:nvGrpSpPr>
<p:cNvPr id="1"
name="" />
<p:cNvGrpSpPr />
<p:nvPr />
</p:nvGrpSpPr>
<p:grpSpPr>
<a:xfrm xmlns:a="https://schemas.openxmlformats.org/drawingml/2006/main" />
</p:grpSpPr>
<p:sp>
<p:nvSpPr>
<p:cNvPr id="2"
name="Title 1" />
<p:cNvSpPr>
<a:spLocks noGrp="1"
xmlns:a="https://schemas.openxmlformats.org/drawingml/2006/main" />
</p:cNvSpPr>
<p:nvPr>
<p:ph />
</p:nvPr>
</p:nvSpPr>
<p:spPr />
<p:txBody>
<a:bodyPr xmlns:a="https://schemas.openxmlformats.org/drawingml/2006/main" />
<a:lstStyle xmlns:a="https://schemas.openxmlformats.org/drawingml/2006/main" />
<a:p xmlns:a="https://schemas.openxmlformats.org/drawingml/2006/main">
<a:endParaRPr lang="en-US" />
</a:p>
</p:txBody>
</p:sp>
</p:spTree>
</p:cSld>
<p:clrMap bg1="lt1"
tx1="dk1"
bg2="lt2"
tx2="dk2"
accent1="accent1"
accent2="accent2"
accent3="accent3"
accent4="accent4"
accent5="accent5"
accent6="accent6"
hlink="hlink"
folHlink="folHlink" />
</p:handoutMaster>