在 2007 Office system 中部署自訂範本

更新日期: 2007年7月

適用於: Office Resource Kit

 

上次修改主題的時間: 2015-03-09

在 2007 Microsoft Office 系統 中,組織可以為數個 2007 Office system 應用程式自訂 [Office 按鈕] 中 [新增文件] 的對話方塊。您可以為 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」區段。請依據所擁有的範本個數,決定要刪除或新增範本區段。然後針對每個範本區段修改並指定下列各項:

  • 在「title」字串提供範本的易記名稱,在「source」 字串提供範本位置。

  • 在第二個「source」字串提供範本縮圖預覽的媒體類型、檔案名稱和位置。

  • 在最後一個「source」字串提供範本大型預覽的媒體類型、檔案名稱和位置。

如果您尚未建立縮圖預覽檔案或大型預覽檔案,則可刪除對應「source」 字串項目的屬性值。如果您未提供要顯示的圖像,在 [新增文件] 對話方塊的縮圖和預覽區域中該範本便會顯示成紅色的 X。

在本範例 XML 檔案中,範本項目的資料夾結構是:

  • **Contoso\Source:**範本檔案 (例如,.dotx)

  • **Contoso\media:**縮圖檔案

  • **Contoso\preview:**預覽檔案

在對此 XML 檔案進行自訂之後,將修改後的檔案儲存在網路資料夾。在您要對使用者部署的登錄機碼中會參考這個位置。

或者,您可以建立 Web 服務以提供 XML 內容。接著建立登錄機碼,將 Office 應用程式導向 XML 檔案所在的網路資料夾或提供此 XML 檔案的 Web 服務。請參閱下一節<設定 Office 使用自訂範本 >以取得詳細資訊。

設定 Office 使用自訂範本

對此 XML 檔案進行自訂之後,請向使用者部署登錄機碼,使 Office 2007 能對 Office 2007 應用程式的 [新增文件] 對話方塊中顯示範本。設定登錄機碼的方式會因範本是位於網路資料夾或是由 Web 服務提供範本而異。

建立下列登錄子機碼項目以提供 XML 檔案位置:

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

在這個登錄子機碼下建立提供者名稱項目 (例如 Contoso),以代表您寫在 XML 檔案中表示要提供的範本群組。提供者名稱不得超過 30 個字元。這個名稱會顯示在 Office 2007 應用程式的 [新增文件] 對話方塊中,自訂範本清單也會隨之顯示。

在提供者名稱之下,指定您建立之自訂 XML 檔案所在的 ServiceURL。您也可以列出要對哪些應用程式提供範本,如下表所述。

數值名稱 數值資料 (資料類型) 描述

ServiceURL

字串

指定下列其中之一:

1. 網路資料夾和 XML 檔案,例如 \\server\public\templates\Contoso\WordTemplates.xml

- 或 -

2. Web 服務的 URL,也就是先前為了部署自訂範本所建立的 XML 檔案所在位置,例如,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:**使用者 [說明] 語言。

  • **LIDU:**使用者介面 (UI) 語言。

例如,Office 應用程式所送出的提供 XML 檔案要求可能是:

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

您可以使用 Office 自訂工具 (OCT) 或其他方法,對使用者部署登錄機碼。在<2007 Office 系統的 Office 自訂工具>的<新增登錄項目>一節中提供了使用 OCT 散佈登錄機碼的詳細資訊。

範例 XML 文字

您可以將下列文字複製到文字編輯器 (例如,[記事本]),並修改內容,以簡化對 Office 應用程式部署自訂範本而建立其所需 XML 的程序。將檔案儲存為 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 檔案

您可以利用本節所提供的內容來驗證自訂 XML 檔案,以提供 Office 應用程式的自訂範本。請將文字複製到文字編輯器 (例如,[記事本]),然後將檔案儲存為 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>