自动打开任务窗格,打开 sourcelocation url,而不是 ID 为 Office.AutoShowTaskpaneWithDocument 的任务窗格

Auto open taskpane, opens sourcelocation url, instead of taskpane with Office.AutoShowTaskpaneWithDocument id

上下文

目前我正在通过新的 Javascript API (office.js) 为 Word 开发一个插件。 Javascript API 为开发人员提供了开发任务窗格的可能性,任务窗格是显示在文档旁边的一列。这些任务窗格充当浏览器并显示 public 或本地托管的网页。通过JavascriptAPI这些页面可以与文档进行交互。

一个加载项可以包含多个任务窗格,可以通过所谓的命令加载项打开。这些命令加载项可以是从功能区中的按钮到右键单击菜单中的选项的任何内容。这些命令加载项和任务窗格的规范在清单中定义。 Word 文档读取此清单,因此可以识别、可以打开哪些页面以及它们应如何在 Office 中显示。

目标

理想情况下,我想创建一些文档,当用户打开这些文档时,这些文档会自动从此加载项中打开某个任务窗格。文档 A 打开任务窗格 A,文档 B 打开任务窗格 B,依此类推。但是,为了这个问题,我只想关注如何从包含多个任务窗格的清单中打开单个任务窗格。文档表明这确实是可能的,如您所见 here。前面提到的 link 指出,这可以通过以下几个步骤来实现。

(1) 托管了一个引用 office.js 的网页。

(2) 创建了一个包含命令加载项和任务窗格的清单。应自动打开的任务窗格的 ID 为 'Office.AutoShowTaskpaneWithDocument'。

  <!--Example code, real manifest at the bottom of the question-->
  <Action xsi:type="ShowTaskpane">
    <TaskpaneId>Office.AutoShowTaskpaneWithDocument</TaskpaneId>
    <SourceLocation resid="Contoso.Taskpane.Url" />
  </Action>

(3) 调整文档的Office Open XML,使其包含一个webextension。 webextension 引用清单和 Office.AutoShowTaskpaneWithDocument id,因此它将打开正确的任务窗格。这是通过添加以下 webextension xml 文档(和 rels 文档,此处未包含)来完成的。

<we:webextension xmlns:we="http://schemas.microsoft.com/office/webextensions/webextension/2010/11" id="[ADD-IN ID PER MANIFEST]">
  <we:reference id="[GUID or Office Store asset ID]" version="[your add-in version]" store="[Pointer to store or catalog]" storeType="[Store or catalog type]"/>
  <we:alternateReferences/>
  <we:properties>
    <we:property name="Office.AutoShowTaskpaneWithDocument" value="true"/>
  </we:properties>
  <we:bindings/>
  <we:snapshot xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"/>
</we:webextension>

问题

该文档确实打开了一个任务窗格,但是它从任务窗格模式集成中的 SourceLocation 打开了 url。用 Office.AutoShowTaskpaneId 标记的任务窗格被完全忽略。

<!--Example code, real manifest at the bottom of the question-->
<!--Begin TaskPane Mode integration. This section is used if there are no VersionOverrides or if the Office client version does not support add-in commands. -->

<Hosts>
  <Host Name="Document" />
</Hosts>
<DefaultSettings>
  <SourceLocation DefaultValue="[baseurl]" />
</DefaultSettings>

<!-- End TaskPane Mode integration.  -->

我假设忽略了包含有关加载项的所有信息的 VersionOverrides 标记。这将导致文档从 DefaultSettings 标签打开回退,从而打开错误的任务窗格。不幸的是,我完全不知道如何解决这个问题。我有最新版本的 Word,因此不应忽略 VersionOverrides 标记。

如有任何帮助,我们将不胜感激!

编辑 我设法解决了它,但不确定是什么导致了解决方案。我没有调整由本地客户端加载项生成的 OOXML,而是使用了由服务器端加载项生成的 OOXML。

虽然我不确定实际问题是什么。我推测 %LOCALAPPDATA%\Microsoft\Office.0\Wef\ 处的 Word 缓存发挥了作用。我所做的唯一更改是使用服务器 运行 加载项调整 OOXML 并预先清理缓存。

附录 1:整个清单,urls 和名称已更改。

<?xml version="1.0" encoding="UTF-8"?>
<!--Created:ce44715c-8c4e-446b-879c-ea9ebe0f09c8-->
<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">

  <!-- Begin Basic Settings: Add-in metadata, used for all versions of Office unless override provided. -->

  <!-- IMPORTANT! Id must be unique for your add-in, if you reuse this manifest ensure that you change this id to a new GUID. -->
  <Id>4a53b5db-f60a-4c32-82ee-2cf3f4954538</Id>

  <!--Version. Updates from the store only get triggered if there is a version change. -->
  <Version>1.0.0.1</Version>
  <ProviderName>[Provider name]</ProviderName>
  <DefaultLocale>nl-NL</DefaultLocale>
  <!-- The display name of your add-in. Used on the store and various places of the Office UI such as the add-ins dialog. -->
  <DisplayName DefaultValue="Add-in Name" />
  <Description DefaultValue="Add-in Description"/>
  <!-- Icon for your add-in. Used on installation screens and the add-ins dialog. -->
  <IconUrl DefaultValue="[baseurl]/Images/Button32x32.png" />

  <!--TODO: Nog toevoegen support pagina gegevens.-->
  <SupportUrl DefaultValue="http://www.contoso.nl" />
  <!-- 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>
  <!--End Basic Settings. -->

  <!--Begin TaskPane Mode integration. This section is used if there are no VersionOverrides or if the Office client version does not support add-in commands. -->

  <Hosts>
    <Host Name="Document" />
  </Hosts>
  <DefaultSettings>
    <SourceLocation DefaultValue="[baseurl]" />
  </DefaultSettings>
  <!-- End TaskPane Mode integration.  -->

  <Permissions>ReadWriteDocument</Permissions>

  <!-- Begin Add-in Commands Mode integration. -->
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">

    <!-- The Hosts node is required. -->
    <Hosts>
      <!-- Each host can have a different set of commands. -->
      <!-- Excel host is Workbook, Word host is Document, and PowerPoint host is Presentation. -->
      <!-- Make sure the hosts you override match the hosts declared in the top section of the manifest. -->
      <Host xsi:type="Document">
        <!-- Form factor. Currently only DesktopFormFactor is supported. -->
        <DesktopFormFactor>

          <!--"This code enables a customizable message to be displayed when the add-in is loaded successfully upon individual install."-->
          <GetStarted>
            <!-- Title of the Getting Started callout. The resid attribute points to a ShortString resource -->
            <Title resid="TextFrag.GetStarted.Title"/>

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

            <!-- Points to a URL resource which details how the add-in should be used. -->
            <LearnMoreUrl resid="TextFrag.GetStarted.LearnMoreUrl"/>
          </GetStarted>

          <!-- Function file is a HTML page that includes the JavaScript where functions for ExecuteAction will be called. 
            Think of the FunctionFile as the code behind ExecuteFunction. -->
          <FunctionFile resid="TextFrag.DesktopFunctionFile.Url" />

          <!-- PrimaryCommandSurface is the main Office Ribbon. -->
          <ExtensionPoint xsi:type="PrimaryCommandSurface">

            <!-- Use OfficeTab to extend an existing Tab. Use CustomTab to create a new tab. -->
            <CustomTab id="contoso.Tab1">

              <!-- Ensure you provide a unique id for the group. Recommendation for any IDs is to namespace using your company name. -->
              <Group id="contoso.Group1">
                <!-- Label for your group. resid must point to a ShortString resource. -->

                <Label resid="contoso.Group1Label" />
                <!-- Icons. Required sizes 16,32,80, optional 20, 24, 40, 48, 64. Strongly recommended to provide all sizes for great UX. -->
                <!-- Use PNG icons. All URLs on the resources section must use HTTPS. -->

                <Icon>
                  <bt:Image size="16" resid="contoso.tpicon_16x16" />
                  <bt:Image size="32" resid="contoso.tpicon_32x32" />
                  <bt:Image size="80" resid="contoso.tpicon_80x80" />
                </Icon>

                <!-- Control. It can be of type "Button" or "Menu". -->
                <Control xsi:type="Button" id="TextFrag.TaskpaneButton">

                  <Label resid="TextFrag.TaskpaneBtn.Label" />

                  <Supertip>
                    <!-- ToolTip title. resid must point to a ShortString resource. -->
                    <Title resid="TextFrag.TaskpaneBtn.Label" />
                    <!-- ToolTip description. resid must point to a LongString resource. -->
                    <Description resid="TextFrag.TaskpaneBtn.Tooltip" />
                  </Supertip>

                  <Icon>
                    <bt:Image size="16" resid="TextFrag.tpicon_16x16" />
                    <bt:Image size="32" resid="TextFrag.tpicon_32x32" />
                    <bt:Image size="80" resid="TextFrag.tpicon_80x80" />
                  </Icon>

                  <!-- This is what happens when the command is triggered (E.g. click on the Ribbon). Supported actions are ExecuteFunction or ShowTaskpane. -->
                  <Action xsi:type="ShowTaskpane">
                    <TaskpaneId>ButtonId1</TaskpaneId>
                    <!-- Provide a URL resource id for the location that will be displayed on the task pane. -->
                    <SourceLocation resid="TextFrag.Taskpane.Url" />
                  </Action>

                </Control>


                <!-- Control. It can be of type "Button" or "Menu". -->
                <Control xsi:type="Button" id="Comm.TaskpaneButton2">
                  <Label resid="Comm.TaskpaneBtn.Label" />

                  <!--TODO: These do not seem to work, remove the reference to the Comm and make it generic.-->
                  <Supertip>
                    <!-- ToolTip title. resid must point to a ShortString resource. -->
                    <Title resid="Comm.TaskpaneBtn.Label" />
                    <!-- ToolTip description. resid must point to a LongString resource. -->
                    <Description resid="Comm.TaskpaneBtn.Tooltip" />
                  </Supertip>

                  <Icon>
                    <bt:Image size="16" resid="Comm.tpicon_16x16" />
                    <bt:Image size="32" resid="Comm.tpicon_32x32" />
                    <bt:Image size="80" resid="Comm.tpicon_80x80" />
                  </Icon>

                  <!-- This is what happens when the command is triggered (E.g. click on the Ribbon). Supported actions are ExecuteFunction or ShowTaskpane. -->
                  <Action xsi:type="ShowTaskpane">
                    <TaskpaneId>ButtonId2</TaskpaneId>
                    <!-- Provide a URL resource id for the location that will be displayed on the task pane. -->
                    <SourceLocation resid="Comm.Taskpane.Url" />
                  </Action>

                </Control>

              </Group>

              <Group id="contoso.Group2">

                <Label resid="contoso.Group2Label" />

                <Icon>
                  <bt:Image size="16" resid="contoso.tpicon_16x16" />
                  <bt:Image size="32" resid="contoso.tpicon_32x32" />
                  <bt:Image size="80" resid="contoso.tpicon_80x80" />
                </Icon>

                <Control xsi:type="Menu" id="Templates.Menu">

                  <Label resid="Templates.Dropdown.Label" />

                  <Supertip>
                    <Title resid="Templates.Dropdown.Label" />
                    <Description resid="Templates.Dropdown.Tooltip" />
                  </Supertip>

                  <Icon>
                    <bt:Image size="16" resid="contoso.tpicon_16x16" />
                    <bt:Image size="32" resid="contoso.tpicon_32x32" />
                    <bt:Image size="80" resid="contoso.tpicon_80x80" />
                  </Icon>

                  <Items>

                    <Item id="Templates.Menu.Item1">

                      <Label resid="Templates.Item1.Label"/>

                      <Supertip>
                        <Title resid="Templates.Item1.Label" />
                        <Description resid="Templates.Item1.Tooltip" />
                      </Supertip>

                      <Icon>
                        <bt:Image size="16" resid="contoso.tpicon_16x16" />
                        <bt:Image size="32" resid="contoso.tpicon_32x32" />
                        <bt:Image size="80" resid="contoso.tpicon_80x80" />
                      </Icon>

                      <Action xsi:type="ShowTaskpane">
                        <TaskpaneId>Office.AutoShowTaskpaneWithDocument</TaskpaneId>
                        <SourceLocation resid="Templates.Taskpane1.Url" />
                      </Action>
                    </Item>

                    <Item id="Templates.Menu.Item2">

                      <Label resid="Templates.Item2.Label"/>

                      <Supertip>
                        <Title resid="Templates.Item2.Label" />
                        <Description resid="Templates.Item2.Tooltip" />
                      </Supertip>

                      <Icon>
                        <bt:Image size="16" resid="contoso.tpicon_16x16" />
                        <bt:Image size="32" resid="contoso.tpicon_32x32" />
                        <bt:Image size="80" resid="contoso.tpicon_80x80" />
                      </Icon>

                      <Action xsi:type="ShowTaskpane">
                        <TaskpaneId>MyTaskPaneID2</TaskpaneId>
                        <SourceLocation resid="Templates.Taskpane2.Url" />
                      </Action>

                    </Item>

                  </Items>

                </Control>

              </Group>

              <!-- Label of your tab -->
              <!-- If validating with XSD it needs to be at the end, we might change this before release -->
              <Label resid="contoso.Tab1.TabLabel" />

            </CustomTab>
          </ExtensionPoint>
        </DesktopFormFactor>
      </Host>
    </Hosts>

    <!-- You can use resources across hosts and form factors. -->
    <Resources>

      <bt:Images>
        <bt:Image id="contoso.tpicon_16x16" DefaultValue="[baseurl]Images/IconTextFrag16x16.png" />
        <bt:Image id="contoso.tpicon_32x32" DefaultValue="[baseurl]Images/IconTextFrag32x32.png" />
        <bt:Image id="contoso.tpicon_80x80" DefaultValue="[baseurl]Images/IconTextFrag80x80.png" />

        <!--Text fragment icons -->
        <bt:Image id="TextFrag.tpicon_16x16" DefaultValue="[baseurl]Images/IconTextFrag16x16.png" />
        <bt:Image id="TextFrag.tpicon_32x32" DefaultValue="[baseurl]Images/IconTextFrag32x32.png" />
        <bt:Image id="TextFrag.tpicon_80x80" DefaultValue="[baseurl]Images/IconTextFrag80x80.png" />

        <!--Committee text fragments -->
        <bt:Image id="Comm.tpicon_16x16" DefaultValue="[baseurl]Images/IconCommittee16x16.png" />
        <bt:Image id="Comm.tpicon_32x32" DefaultValue="[baseurl]Images/IconCommittee32x32.png" />
        <bt:Image id="Comm.tpicon_80x80" DefaultValue="[baseurl]Images/IconCommittee80x80.png" />


      </bt:Images>

      <bt:Urls>
        <!--General-->
        <!--TODO: Solidify function file.-->
        <!--TODO: Solidify GetStarted.LearnMoreUrl-->

        <!--Text Fragments-->
        <bt:Url id="TextFrag.DesktopFunctionFile.Url" DefaultValue="[baseurl]/Functions/FunctionFile.html" />
        <bt:Url id="TextFrag.Taskpane.Url" DefaultValue="[baseurl]/Textfragments" />
        <bt:Url id="TextFrag.GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812" />

        <!--Committees-->
        <bt:Url id="Comm.DesktopFunctionFile.Url" DefaultValue="[baseurl]/Functions/FunctionFile.html" />
        <bt:Url id="Comm.Taskpane.Url" DefaultValue="[baseurl]/Communication" />
        <bt:Url id="Comm.GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812" />

        <!--Templates-->
        <bt:Url id="Templates.Taskpane1.Url" DefaultValue="[baseurl]/Templates/Letter" />
        <bt:Url id="Templates.Taskpane2.Url" DefaultValue="[baseurl]/InsertCommittee" />

      </bt:Urls>

      <!-- ShortStrings max characters==125. -->
      <bt:ShortStrings>
        <!--General-->
        <bt:String id="contoso.Tab1.TabLabel" DefaultValue="Contoso" />
        <bt:String id="contoso.Group1Label" DefaultValue="Group1" />
        <bt:String id="contoso.Group2Label" DefaultValue="Group2" />

        <!--Text Fragments-->
        <bt:String id="TextFrag.TaskpaneBtn.Label" DefaultValue="Text fragments" />
        <bt:String id="TextFrag.GetStarted.Title" DefaultValue="Description" />

        <!--Committees-->
        <bt:String id="Comm.TaskpaneBtn.Label" DefaultValue="Communication" />
        <bt:String id="Comm.GetStarted.Title" DefaultValue="Description" />

        <!--Templates-->
        <bt:String id="Templates.Dropdown.Label" DefaultValue="Templates" />
        <bt:String id="Templates.Item1.Label" DefaultValue="Letter" />
        <bt:String id="Templates.Item2.Label" DefaultValue="Letter 2" />

      </bt:ShortStrings>

      <!-- LongStrings max characters==250. -->
      <bt:LongStrings>
        <!--General-->
        <bt:String id="Comm.GetStarted.Description" DefaultValue="Description" />

        <!--Text Fragments-->
        <bt:String id="TextFrag.TaskpaneBtn.Tooltip" DefaultValue="Description" />
        <bt:String id="TextFrag.GetStarted.Description" DefaultValue="Description" />

        <!--Committees-->
        <bt:String id="Comm.TaskpaneBtn.Tooltip" DefaultValue="Description" />

        <!--Templates-->
        <bt:String id="Templates.Dropdown.Tooltip" DefaultValue="Description" />
        <bt:String id="Templates.Item1.Tooltip" DefaultValue="Description" />
        <bt:String id="Templates.Item2.Tooltip" DefaultValue="Description" />


      </bt:LongStrings>
    </Resources>
  </VersionOverrides>
  <!-- End Add-in Commands Mode integration. -->

</OfficeApp>

您只能将一个 TaskpaneId 设置为 Office.AutoShowTaskpaneWithDocument。分配给该任务窗格的 SourceLocation 的 URL 在清单中进行了硬编码。在你的例子中是 [baseurl]/Templates/Letter。因此,您为此加载项启用了自动打开功能的每个文档都应该自动打开信件。没有办法在另一个文档上安装完全相同的加载项(因此,完全相同的清单)并自动打开不同的页面。 加载项是否自动打开到 [baseurl]/Templates/Letter?如果没有,您确定有一个具有该名称和路径的文件吗?它是 HTML 文件吗?当加载项为 运行 时,如果您将浏览器 window 导航到那个 URL 会发生什么情况?页面是否在浏览器中加载?