在 2007 Office system 中部署自定义模板

更新时间: 2007年7月

应用到: Office Resource Kit

 

上一次修改主题: 2015-03-09

在 2007 Microsoft Office system中,组织可以在“Office 按钮”上为多个 2007 Office system 应用程序自定义“新建文档”对话框。您可以为“新建文档”对话框创建和部署用于 Microsoft Office Word 2007、Microsoft Office PowerPoint 2007 和 Microsoft Office Excel 2007 的模板。例如,您可以提供适用于 Office Word 2007 文档的自定义模板,以供用户在新建文档时进行选择。本主题介绍如何创建和提供自定义模板。

Note注意
在 2007 Office system中,用于自定义“文件”菜单的对象模型支持已被本主题中描述的自定义步骤所取代。

在“新建文档”对话框中,自定义模板显示在左侧的“自定义”标题之下,如下所示。在本例中,自定义模板在“Contoso”目录中进行分组。

新建文档对话框与自定义模板

按照以下步骤,在“新建文档”对话框中提供自定义模板:

  1. 创建并保存适用于一个或多个应用程序的自定义模板。

  2. 将模板复制到网络文件夹,或使模板可用于网站上。

  3. 为模板创建缩略图和预览图像文件(可选)。

  4. 修改示例 XML 文本以提供特定于自定义模板的信息。使用所提供的 XSD 文本验证您的自定义文件。请参阅本主题后面的示例 XML 文本和验证用于自定义模板的 XML 文件。

  5. 将自定义的 XML 文件保存到网络文件夹中。通过使用注册表项指定到该文件夹的路径,或者从 Web 服务中提供 XML 文件。

创建并保存自定义模板

创建 Office system 应用程序模板的过程很简单。只需在应用程序中打开新文档或现有文档,然后进行自定义。将此文档另存为模板。

例如,使用以下步骤可在 Office Word 2007 中创建模板。

在 Office Word 2007 中创建模板

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

  2. 自定义该文档。

  3. 单击“Office 按钮”,指向“另存为”,然后单击“Word 模板”。

  4. 在“文件名:”字段中,键入模板的名称,然后单击“确定”。

Office Word 2007 模板文件使用 .dotx 扩展名进行保存。其他 Office 应用程序模板的文件扩展名与此类似;例如,Microsoft Office Excel 模板具有 .xltx 扩展名。

在创建并保存组织所需的自定义模板后,将模板文件复制到网络文件服务器,或在网站上提供这些文件。

创建缩略图和预览文件

创建自定义模板的缩略图和预览文件(例如,使用屏幕快照和图像编辑器来创建)。可以在 XML 文件中指定缩略图和预览文件的图像类型。按照在 XSD 文件中指定的方式从各种文件图像类型中进行选择。例如,您可以使用 GIF 图像类型。

下表中提供了文件的近似维度。

预览类型 宽度 高度

缩略图

100

120

预览

256

350

在“新建文档”对话框的“Microsoft Office Online”部分中单击某个模板,以获得缩略图和预览文件的示例。例如,在 Office Word 2007 中单击“议程”。

创建描述自定义模板的自定义 XML 文件

2007 Office system引用 XML 文件来填充在“新建文档”对话框中显示的项。要在“新建文档”中包括自定义模板,您可以自定义并提供一个 XML 文件(其中包含要显示的模板的位置以及模板的缩略图和预览图像的位置)。完成配置后,将会在“自定义”标题下的“新建文档”对话框中显示自定义模板。

要简化创建 XML 文件的过程,请根据本主题后面的示例 XML 文本部分中提供的文本创建自定义 XML。

XML 中具有对应于每种模板类型的单独部分(例如,Word 模板),并且在这些部分中具有对应于每个自定义模板的部分:TEMPLATE 1、TEMPLATE 2,依此类推。示例 XML 包括对应于 Office Word 2007 模板的部分 ( application id = "WD")。还可能具有对应于 Office Excel 2007 模板的部分 (application id = "XL") 和 Office PowerPoint 2007 模板的部分 (application id = "PP")。

示例 XML 文件包括四个“featuredtemplate”部分。根据您拥有的模板数,删除或添加模板部分。然后,修改各个条目,以便为每个模板部分指定以下各项:

  • 在“标题”字符串中指定模板的友好名称,在“源”字符串中指定模板的位置。

  • 在下一个“源”字符串中指定模板的缩略图预览的媒体类型、文件名和位置。

  • 在最后一个“源”字符串中指定模板的大型预览的媒体类型、文件名和位置。

如果您尚未创建缩略图预览文件或大型预览文件,则可以删除相应的“源”字符串条目的属性值。如果您没有提供要显示的图像,则将对“新建文档”对话框的缩略图和预览区域中的模板显示一个红色 X。

在示例 XML 文件中,模板条目的文件夹结构为:

  • **Contoso\Source:**模板文件(例如,.dotx)

  • **Contoso\media:**缩略图文件

  • **Contoso\preview:**预览文件

自定义 XML 文件后,请将修改的文件保存在网络文件夹中。在您向用户部署的注册表项中将引用此位置。

此外,您可以创建一个 Web 服务以提供 XML 内容。您可以创建一个注册表项,以便将 Office 应用程序定向到网络文件夹或 Web 服务以获得 XML 文件。有关详细信息,请参阅下一节“将 Office 配置为使用自定义模板”。

将 Office 配置为使用自定义模板

自定义 XML 文件后,向用户部署注册表项,以使 Office 2007 可以在 Office 2007 应用程序的“新建文档”对话框中显示您的模板。您可以按不同方式配置注册表项,具体取决于模板是位于网络文件夹上,还是由 Web 服务提供。

创建以下注册表子项条目,以提供 XML 文件的位置:

HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\Spotlight\Providers

对于您要提供的在 XML 文件中描述的模板组,在此注册表子项(例如,Contoso)下创建一个提供程序名称条目。提供程序名称必须为 30 个字符或更少字符。名称将显示在 Office 2007 应用程序的“新建文档”对话框中,后面跟随自定义模板的列表。

在提供程序名称下,指定您创建的自定义 XML 文件所在的 ServiceURL。您还可以选择列出您为其提供模板的应用程序,如下表所述。

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

ServiceURL

字符串

指定两者之一:

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

- 或 -

2. 您为部署自定义模板所创建的 XML 文件所在的 Web 服务的 URL;例如,https://www.contoso.com。有关此选项的详细信息描述如下。

Application

字符串

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

ServiceURL 字符串是一个提供程序,当您使用 Web 服务提供模板时,Office 应用程序将向其发送针对 XML 文件的请求。Web 服务通过提供 XML 文件进行响应。来自 Office 应用程序的请求包括以下参数:

  • **App:**Office 应用程序值(XL、WD 或 PP)。

  • **LIDUser:**用户语言。

  • **LIDHelp:**用户帮助语言。

  • **LIDUI:**用户界面 (UI) 语言。

例如,Office 应用程序对于 XML 文件的请求可能为:

https://www.contoso.com?app="XL"&liduser=0409&lidhelp=0409&lidui=0409

可以使用 Office 自定义工具 (OCT) 或其他方法向用户部署该注册表项。有关使用 OCT 分发注册表项的信息,请参阅 2007 Office system 中的 Office 自定义工具中的添加注册表项部分。

示例 XML 文本

可以将以下文本复制到文本编辑器(如记事本)中,并修改内容以简化创建 XML 的过程(使用 Office 应用程序部署自定义模板时需要此文件)。将此文件保存为 XML 文件;例如,ContosoTemplates.xml。

要验证 XML 文件,请使用下一节验证用于自定义模板的 XML 文件中提供的文本。

<?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="2007-01-01" enddate="2009-03-02">

            <!-- 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 文件

请使用本节提供的文本来验证为在 Office 应用程序中提供自定义模板而使用的自定义 XML 文件。将此文本复制到文本编辑器(如记事本)中,然后将此文件另存为 XSD 文件;例如,OfficeTemplates.xsd。

<?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 new FileNew dialog 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>