在 Office 2010 中部署自定义模板

 

适用于: Office 2010

上一次修改主题: 2016-11-29

在 Microsoft Office 2010 中,您可创建和部署用户在创建新文档、演示文稿或工作表时可选择的模板。

您可为 Microsoft Word 2010、PowerPoint 2010 和 Excel 2010 用户创建和部署这些 Office 2010 模板。

本文内容:

  • 创建和部署自定义模板

  • 创建模板

  • 创建缩略图和预览文件

  • 创建描述自定义模板、缩略图和预览文件的 XML 配置文件

  • 部署能够让 Office 读取 XML 配置文件的注册表项

创建和部署自定义模板

您可以创建自定义模板并使它们可供用户在“可用模板”窗格中使用,而用户单击“文件”菜单上的“新建”时可显示该窗格。该过程包括如下步骤:

  1. 创建模板。

  2. 创建缩略图和预览文件。

  3. 创建描述自定义模板、缩略图和预览文件的 XML 配置文件。

  4. 部署能够让 Office 读取 XML 配置文件的注册表项。

创建模板

要创建自定义模板,请打开一个新的或现有文档、工作表或演示文稿,进行自定义设置,然后将该文件另存为网络文件夹或网站上的模板。

以下示例显示如何在 Word 2010 中创建模板。这些步骤与在 Excel 2010 和 PowerPoint 2010 中创建模板的步骤几乎完全相同。有关创建模板的详细信息,请参阅了解 Office 2010 中的模板 (https://go.microsoft.com/fwlink/?linkid=212947\&clcid=0x804)。

在 Word 2010 中创建模板

  1. 在 Word 2010 中打开一个新的或现有文档。

  2. 自定义该文档。

  3. 在“文件”菜单上,单击“另存为”。

  4. 在树窗格中,浏览到网络上的共享文件夹(也可以是 Web 服务器上的文件夹)。

  5. 在“文件名”框中,键入要用于该模板的名称。

  6. 在“保存类型”框中,选择“Word 模板”,然后单击“保存”。

创建缩略图和预览文件(可选)

这是一个可选步骤,但缩略图和预览文件可为用户提供帮助,因为它们可以让用户快速查看和选择模板。要查看缩略图和预览文件的示例,请单击“可用模板”窗格中的“样本模板”。如果决定不为自定义模板创建缩略图和预览文件,用户将在“可用模板”窗格中看到模板名称。此时将显示一个红色的 X 而不显示缩略图和预览图像。

创建缩略图和预览文件

  1. 使用屏幕截图和图像编辑器创建缩略图和预览文件。建议使用以下维度:

    预览类型 宽度 高度

    缩略图

    100

    120

    预览

    256

    350

  2. 将文件保存为以下其中一种文件类型:.jpg, .png, .bmp, .gif。

创建描述自定义模板、缩略图和预览文件的 XML 配置文件

要使自定义模板显示在“可用模板”窗格中,则必须创建 XML 配置文件。Office 2010 将参考该文件来确定如何查找和显示模板、缩略图和预览文件。

创建 XML 配置文件

  1. 复制本文中提供的示例 xml 文件文本,然后将其粘贴到文本编辑器(如“记事本”)中。有关详细信息,请参阅 XML 配置文件的示例文本。

  2. 根据需要编辑示例文本。

    可以使用本文中提供的示例架构定义 (XSD) 文件文本创建 XSD 文件,以验证 XML 配置文件(可选)。要创建 XSD 文件,请将示例验证文本复制到文本编辑器中,然后将其另存为 XSD 文件;例如,OfficeTemplates.xsd。有关详细信息,请参阅 XML 架构定义 (XSD) 文件的示例文本。

  3. 将已编辑的文本另存为 XML 文件(例如,ContosoTemplates.xml),然后将其保存到网络共享(也可以是 Web 服务器上的文件夹)。

XML 配置文件的示例文本

可以将以下文本复制到文本编辑器(如“记事本”)中,配置该文本以定义自定义模板,然后将该文件另存为 XML 文件;例如,ContosoTemplates.xml

示例 XML 仅包含一个 application id 节,对于 Word 2010 模板:application id = "WD"。可以为 Excel 2010 和 PowerPoint 添加节,方法是复制 <o:application id="WD"></o:application> 之间的所有内容,然后将 application id 参数更改为 "XL"(对于 Excel)或 "PP"(对于 PowerPoint 2010)。

每个 featuredtemplate 节表示 application id 中的一个自定义模板。示例 XML 包括四个 featuredtemplate 节。但是,可以根据拥有的自定义模板数量添加或删除节。对于每个 featuredtemplate,请配置标题、媒体(缩略图)和预览信息以描述模板。如果没有创建缩略图或预览文件,则可以删除对应于媒体和预览信息的属性值。如果没有提供要显示的缩略图和预览图像,则“可用模板”窗格中的缩略图和预览图像会显示一个红色的 X。

<?xml version="1.0" encoding="utf-8"?>
<o:featuredcontent lcid="1033" xmlns:o="urn:schemas-microsoft-com:office:office">
    <o:application id="WD">
        <o:featuredtemplates startdate="2011-03-01" enddate="2013-03-01">

            <!-- TEMPLATE 1 -->
            <o:featuredtemplate title="Template 1" source="\\server1\public\templates\Contoso\Source\1.dotx" >
                <o:media mediatype="gif" filename="1.gif" source="\\server1\public\templates\Contoso\media\1.gif" />
                <o:preview filename="1big.gif" source="\\server1\public\templates\Contoso\preview\1.gif" />
            </o:featuredtemplate>

            <!-- TEMPLATE 2 -->
            <o:featuredtemplate title="Template 2" source="\\server1\public\templates\Contoso\Source\2.dotx" >
                <o:media mediatype="gif" filename="2.gif" source="\\server1\public\templates\Contoso\media\2.gif" />
                <o:preview filename="2big.gif" source="\\server1\public\templates\Contoso\preview\2.gif" />
            </o:featuredtemplate>

            <!-- TEMPLATE 3 -->
            <o:featuredtemplate title="Template 3" source="\\server1\public\templates\Contoso\Source\3.dotx" >
                <o:media mediatype="gif" filename="3.gif" source="\\server1\public\templates\Contoso\media\3.gif" />
                <o:preview filename="3big.gif" source="\\server1\public\templates\Contoso\preview\3.gif" />
            </o:featuredtemplate>

            <!-- TEMPLATE 4 -->
            <o:featuredtemplate title="Template 4" source="\\server1\public\templates\Contoso\Source\4.dotx" >
                <o:media mediatype="gif" filename="4.gif" source="\\server1\public\templates\Contoso\media\4.gif" />
                <o:preview filename="4big.gif" source="\\server1\public\templates\Contoso\preview\4.gif" />
            </o:featuredtemplate>

        </o:featuredtemplates>
    </o:application>
</o:featuredcontent>

XML 架构定义 (XSD) 文件的示例文本

可以使用架构定义 (XSD) 验证 XML 文件。要创建 XSD 文件,请将以下文本复制到文本编辑器中,然后将其另存为 XSD 文件;例如,OfficeTemplates.xsd

然后可以将 XSD 文件与可执行架构验证的 XML 编辑器(如 XML Notepad 2007)一起使用。

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="urn:schemas-microsoft-com:office:office" elementFormDefault="qualified"
  xmlns="urn:schemas-microsoft-com:office:office" xmlns:o="urn:schemas-microsoft-com:office:office"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="featuredcontent">
<xs:annotation>
  <xs:documentation>
This is the schema for custom spotlight providers in the Available Templates pane that users see when they click New on the File menu in Word, Excel, and PowerPoint.
Copyright (c) Microsoft Corporation.
  </xs:documentation>
</xs:annotation>
<xs:complexType>
  <xs:sequence>
<xs:element name="application" minOccurs="1" maxOccurs="unbounded">
  <xs:annotation>
<xs:documentation>
  Include one application block for every application you have custom templates for
</xs:documentation>
  </xs:annotation>
  <xs:complexType>
<xs:sequence>
  <xs:element name="featuredtemplates" minOccurs="0" maxOccurs="1">
<xs:complexType>
  <xs:sequence>
<xs:element name="featuredtemplate" minOccurs="0" maxOccurs="unbounded">
  <xs:complexType>
<xs:sequence>
  <xs:element name="media" type="CT_ImageAttributes">
<xs:annotation>
  <xs:documentation>
The media element refers to the thumbnail (small) image for the template
  </xs:documentation>
</xs:annotation>
  </xs:element>
  <xs:element name="preview" type="CT_ImageAttributes">
<xs:annotation>
  <xs:documentation>
The preview element refers to the preview (large) image for the template
  </xs:documentation>
</xs:annotation>
  </xs:element>
</xs:sequence>
<xs:attribute name="title" type="ST_SpotlightString" />
<xs:attribute name="source" type="xs:anyURI" />
  </xs:complexType>
</xs:element>
  </xs:sequence>
  <xs:attribute name="startdate" type="ST_Date" use="required" />
  <xs:attribute name="enddate" type="ST_Date" use="required" />
</xs:complexType>
  </xs:element>
</xs:sequence>
<xs:attribute name="id" type="ST_Application" use="required" />
  </xs:complexType>
</xs:element>
  </xs:sequence>
  <xs:attribute name="lcid" type="xs:unsignedShort" use="required" />
</xs:complexType>
  </xs:element>
  <xs:simpleType name="ST_Application">
<xs:annotation>
  <xs:documentation>
Specifies the application for which to deliver spotlight content
  </xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
  <xs:enumeration value="WD" />
  <xs:enumeration value="XL" />
  <xs:enumeration value="PP" />
</xs:restriction>
  </xs:simpleType>
  <xs:complexType name="CT_ImageAttributes">
<xs:sequence />
<xs:attribute name="mediatype" type="ST_MediaType">
</xs:attribute>
<xs:attribute name="filename" type="ST_Filename" use="required" />
<xs:attribute name="source" type="xs:anyURI" use="required" />
<xs:attribute name="alttext" type="ST_SpotlightString" use="optional" />
  </xs:complexType>
  <xs:simpleType name="ST_SpotlightString">
<xs:restriction base="xs:string">
  <xs:maxLength value="255" />
  <xs:minLength value="1" />
</xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="ST_MediaType">
<xs:restriction base="xs:string">
  <xs:enumeration value="jpg" />
  <xs:enumeration value="png" />
  <xs:enumeration value="bmp" />
  <xs:enumeration value="gif" />
</xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="ST_Date">
<xs:annotation>
  <xs:documentation>
Date must be specified in YYYY-MM-DD format
  </xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
  <xs:pattern value="[0-9]{4}-[0-9]{2}-[0-9]{2}" />
</xs:restriction>
  </xs:simpleType>
  <xs:simpleType name="ST_Filename">
<xs:annotation>
  <xs:documentation>
Filename cannot contain \ ? | > : / * " or less-than, must be less than 260 chars, and have a valid extension.
Example: image.jpg
  </xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
  <xs:pattern value="[^\\\?|&gt;&lt;:/\*&quot;]{1,259}" />
</xs:restriction>
  </xs:simpleType>
</xs:schema>

部署能够让 Office 读取 XML 配置文件的注册表项

自定义 XML 文件后,必须部署注册表项,以便让 Office 2010 在“可用模板”窗格中显示您的模板。必须为每个访问自定义模板的用户部署注册表项。

创建和部署注册表项

  1. 创建以下注册表项:

    HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Common\Spotlight\Providers\[ProviderName]
    

    [ProviderName] 项表示 XML 文件中描述的一组模板(例如,Contoso),其显示在受影响的 Office 2010 应用程序的“自定义模板”下的“可用模板”窗格中。输入的名称必须等于或小于 30 个字符。

  2. [ProviderName] 项下

    • 创建名为 ServiceURL 的新字符串值,用于表示已创建的 XML 文件所在的位置。

    • 还可以创建名为 Application 的字符串值,它将列出为其提供模板的应用程序。

      下表对这些字符串进行了描述:

      值名称 数值数据(数据类型) 说明

      ServiceURL

      字符串

      指定以下其中任何一项:

      • 网络文件夹和 XML 文件;例如,\\server\public\templates\Contoso\WordTemplates.xml

      • Web 服务的 URL,您创建的用于部署自定义模板的 XML 文件所在的位置;例如,https://www.contoso.com

      Application

      字符串

      可选:为 Word 模板指定 WD、为 Excel 模板指定 XL 或为 PowerPoint 模板指定 PP。如果一组模板包含多个应用程序的模板,请不要包含此注册表项。

  3. 使用 Office 自定义工具 (OCT) 或另一种工具将注册表项部署到用户。有关如何使用 OCT 分发注册表项的详细信息,请参阅 Office Customization Tool in Office 2010一文中的添加注册表项