如何在word 2016中创建带按钮的新标签页

How to create new tab with buttons in word 2016

我是 office 365 的新手。我使用 javacript api 为 word 2016 开发了一个任务窗格插件 (testaddin)。在 word 2016 中,我想创建新选项卡 (testtab) 并向其添加一个按钮。单击该按钮后,我需要在任务窗格中显示我的 testaddin。我在这里有示例清单文件。 https://github.com/OfficeDev/Office-Add-in-Commands-Samples/tree/master/Word。下载文件后放置清单文件的位置。 我已经有一个共享目录,其中包含我的 testaddin 清单文件及其在任务窗格中的加载。 任何帮助将不胜感激。

您从 GitHub 引用的清单是可运行的。我们可以根据我们的要求修改它,并将它也部署到共享文件夹中。例如,要在功能区上创建一个新选项卡而不是使用内置选项卡,我们需要使用“CustomTab”而不是“OfficeTab”。

详细步骤如下:

  1. 修改清单如下(需要修改源 位置和图像根据您的业务需求)

<?xml version="1.0" encoding="UTF-8"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">
  <!-- BeginBasicSettings: Add-in metadata, used for all versions of Office unless override provided -->

  <!--IMPORTANT! Id must be unique for your add-in, if you clone this manifest ensure that you change this id to your own GUID -->
  <Id>651a32a9-ab8a-4579-ac9f-df1a11a64e54</Id>

  <!--Version. Updates from the store only get triggered if there is a version change -->
  <Version>1.0.0.0</Version>
  <ProviderName>Contoso</ProviderName>
 <DefaultLocale>en-US</DefaultLocale>
  <!-- The display name of your add-in. Used on the store and various placed of the Office UI such as the add-ins dialog -->
  <DisplayName DefaultValue="Citations" />
  <Description DefaultValue="Citations Example"/>

  <!--Icon for your add-in. Used on installation screens and the add-ins dialog -->
  <IconUrl DefaultValue="https://i.imgur.com/LltG56v.png" />

  <!--Todo: Add requirement sets and remove  commenting of high res icon -->
  <!--The HighResolutionIcon element is commented because it is valid only for 1.1 (or above) versions of the manifest.
          To use this property, convert this manifest to version 1.1 by adding an API set in the Activation tab of the manifest editor.-->
  <!--<HighResolutionIconUrl DefaultValue="https://i.imgur.com/MPuvMiq.png" />-->

  <!--Domains that will be allowed when navigating. For example, if you use ShowTaskpane and then have an href link, navigation will only be allowed if the domain is on this list -->
  <AppDomains>
    <AppDomain>AppDomain1</AppDomain>
    <AppDomain>AppDomain2</AppDomain>
    <AppDomain>AppDomain3</AppDomain>
  </AppDomains>
  <!--EndBasicSettings-->

  <!--BeginTaskpaneMode integration. Office 2013 and any client that doesn't understand commands will use this section.
    This section will also be used if there are no VersionOverrides -->
  <Hosts>
    <Host Name="Document" />
  </Hosts>
  <DefaultSettings>
    <SourceLocation DefaultValue="https://addinwithfabric.azurewebsites.net/index.html" />
  </DefaultSettings>
  <!--EndTaskpaneMode integration -->

  <Permissions>ReadWriteDocument</Permissions>

  <!--BeginAddinCommandsMode integration-->
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
    <!-- Optional, override the description of the Add-in -->
    <Description resid="residToolTip" />
    <!--Required, hosts node. Each host can have a different set of commands -->
    <Hosts>
      <!--Specific host. Workbook=Excel, Document=Word, Presentation=PowerPoint -->
      <Host xsi:type="Document">
        <!-- Form factor. Currenly only DesktopFormFactor is supported. We will add TabletFormFactor and PhoneFormFactor in the future-->
        <DesktopFormFactor>

          <!--GetStarted information used on the callout that appears when installing the add-in. 
            Ensure you have build 16.0.6769 or above for GetStarted section to work-->
          <GetStarted>
            <!--Title of the Getting Started callout. resid points to a ShortString resource -->
            <Title resid="Contoso.GetStarted.Title"/>

            <!--Description of the Getting Started callout. resid points to a LongString resource -->
            <Description resid="Contoso.GetStarted.Description"/>

            <!--Not used right now but you need to provide a valid resource. We will add code in the future to consume this URL. 
                                               resid points to a Url resource -->
            <LearnMoreUrl resid="Contoso.GetStarted.LearnMoreUrl"/>
          </GetStarted>

          <!--Function file is an html page that includes the javascript where functions for ExecuteAction will be called. 
            Think of the FunctionFile as the "code behind" ExecuteFunction 
            This sample doesn't use this file, just adding the element for reference-->

          <!--PrimaryCommandSurface==Main Office Ribbon-->
          <ExtensionPoint xsi:type="PrimaryCommandSurface">

            <!--Use OfficeTab to extend an existing Tab. Use CustomTab to create a new tab -->
            <!-- Documentation includes all the IDs currently tested to work -->
            <CustomTab id="Contoso.Citations">
              <!--Group. Ensure you provide a unique id. Recommendation for any IDs is to namespace using your companyname-->
              <Group id="Contoso.Citations.Group1Id1">
                <!--Label for your group. resid must point to a ShortString resource -->
                <Label resid="residLabel4" />
                <!--Icons. Required sizes 16,31,80, optional 20, 24, 40, 48, 64. Strongly recommended to provide all sizes for great UX -->
                <!--Use PNG icons and remember that all URLs on the resources section must use HTTPS -->
                <Icon>
                  <bt:Image size="16" resid="icon1_16x16" />
                  <bt:Image size="32" resid="icon1_32x32" />
                  <bt:Image size="80" resid="icon1_80x80" />
                </Icon>
                <!--Control. It can be of type "Button" or "Menu" -->
                <Control xsi:type="Button" id="Button3Id1">
                  <!--Label for your button. resid must point to a ShortString resource -->
                  <Label resid="residLabel3" />
                  <Supertip>
                    <!--ToolTip title. resid must point to a ShortString resource -->
                    <Title resid="residLabel" />
                    <!--ToolTip description. resid must point to a LongString resource -->
                    <Description resid="residToolTip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="icon1_16x16" />
                    <bt:Image size="32" resid="icon3_32x32" />
                    <bt:Image size="80" resid="icon1_80x80" />
                  </Icon>
                  <!--This is what happens when the command is triggered (E.g. click on the Ribbon). Supported actions are ExecuteFuncion or ShowTaskpane-->
                  <Action xsi:type="ShowTaskpane">
                    <!--Provide a url resource id for the location that will be displayed on the taskpane -->
                    <SourceLocation resid="residUnitConverterUrl" />
                  </Action>
                </Control>
              </Group>
              <Label resid="residLabel4" />
            </CustomTab>
          </ExtensionPoint>
        </DesktopFormFactor>
      </Host>
    </Hosts>
    <Resources>
      <bt:Images>
        <bt:Image id="icon1_16x16" DefaultValue="https://i.imgur.com/xV3upTT.png">
          <bt:Override Locale="ja-jp" Value="https://i.imgur.com/xV3upTT.png" />
        </bt:Image>
        <bt:Image id="icon1_32x32" DefaultValue="https://i.imgur.com/kBw0iKX.png">
          <bt:Override Locale="ja-jp" Value="https://i.imgur.com/kBw0iKX.png" />
        </bt:Image>
        <bt:Image id="icon1_80x80" DefaultValue="https://i.imgur.com/xV3upTT.png">
          <bt:Override Locale="ja-jp" Value="https://i.imgur.com/xV3upTT.png" />
        </bt:Image>
        <bt:Image id="icon2_32x32" DefaultValue="https://i.imgur.com/LltG56v.png">
        </bt:Image>
        <bt:Image id="icon3_32x32" DefaultValue="https://i.imgur.com/6WiJTG0.png">
        </bt:Image>
      </bt:Images>
      <bt:Urls>

        <bt:Url id="residUnitConverterUrl" DefaultValue="https://addinwithfabric.azurewebsites.net/index.html">
        </bt:Url>
        <!--LearnMore URL currently not used -->
        <bt:Url id="Contoso.GetStarted.LearnMoreUrl" DefaultValue="https://odsample.azurewebsites.net/Pages/GetStarted.html">
        </bt:Url>
      </bt:Urls>
      <bt:ShortStrings>
        <bt:String id="residLabel" DefaultValue="Get Data">
          <bt:Override Locale="ja-jp" Value="JA-JP Multiple Buttons" />
        </bt:String>
        <bt:String id="residLabel2" DefaultValue="Save Data">
          <bt:Override Locale="ja-jp" Value="JA-JP Multiple Buttons" />
        </bt:String>
        <bt:String id="residLabel3" DefaultValue="Search Citation">
          <bt:Override Locale="ja-jp" Value="JA-JP Multiple Buttons" />
        </bt:String>
        <bt:String id="residLabel4" DefaultValue="Web Citations">
          <bt:Override Locale="ja-jp" Value="JA-JP Multiple Buttons" />
        </bt:String>
        <bt:String id="residLabel5" DefaultValue="Another Command">
          <bt:Override Locale="ja-jp" Value="JA-JP Multiple Buttons" />
        </bt:String>
        <bt:String id="Contoso.GetStarted.Title" DefaultValue="Citation Sample Loaded Successfully">
          <bt:Override Locale="ja-jp" Value="JA-JP Get Started Title" />
        </bt:String>
      </bt:ShortStrings>
      <bt:LongStrings>
        <bt:String id="residToolTip" DefaultValue="Multiple Buttons Tooltip">
          <bt:Override Locale="ja-jp" Value="JA-JP Multiple Buttons Tooltip" />
        </bt:String>
        <bt:String id="Contoso.GetStarted.Description" DefaultValue="Get going by opening the REFERENCES tab on the Ribbon then click WEB CITATIONS>SEARCH CITATION button">
          <bt:Override Locale="ja-jp" Value="JA-JP Get Started Title" />
        </bt:String>
      </bt:LongStrings>
    </Resources>
  </VersionOverrides>
</OfficeApp>

  1. 将清单复制到您配置为的共享文件夹 Word 的“可信目录”。
  2. 从共享文件夹中插入 Office 应用程序,您可以 查看新标签“Web Citations” 丝带

请确保遵循文档。您下载的清单不需要任何更改,只是为了测试它确保遵循以下链接:

  1. 插件命令介绍http://dev.office.com/docs/add-ins/design/add-in-commands
  2. 查看示例:https://github.com/OfficeDev/Office-Add-in-Commands-Samples/blob/master/README.md
  3. 使用网络共享进行测试:https://dev.office.com/docs/add-ins/publish/create-a-network-shared-folder-catalog-for-task-pane-and-content-add-ins

如果您遵循这些文档,您应该能够进行测试。如果这些页面上的信息没有用,或者如何改进,请告诉我!..

谢谢!