【问题标题】:Auto open taskpane, opens sourcelocation url, instead of taskpane with Office.AutoShowTaskpaneWithDocument id自动打开任务窗格,打开 sourcelocation url,而不是带有 Office.AutoShowTaskpaneWithDocument id 的任务窗格
【发布时间】:2018-01-17 15:51:16
【问题描述】:

上下文

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

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

目标

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

(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\16.0\Wef\ 的 Word 缓存起了作用。我所做的唯一更改是使用服务器运行插件调整 OOXML 并事先清理缓存。

附录 1:整个清单、网址和名称已更改。

<?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>

【问题讨论】:

  • 您能否分享清单的资源部分,以便我们可以看到 resid: Contoso.Taskpane.Url 的值?另外,我认为说“文档 A 打开任务窗格 A,文档 B 打开任务窗格 B,等等”是不正确的。当我阅读文档并查看标记时,看起来给定的加载项只能将一个任务窗格设置为自动打开。它会在每个安装了插件的文档上打开相同的 URL。
  • 嗨 Rick,这些都是例子,我会在稍后与你分享真实的清单并进行一些调整。关于多个任务窗格,我假设 OOXML 中指定的 Office.AutoShowTaskpaneWithDocument id 可以是任务窗格的任何 id。因此,不同的文档可以指定要打开的不同任务窗格。
  • 我可以从js调整excel表格的OOXML吗?

标签: openxml office-js office-addins word-addins


【解决方案1】:

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

【讨论】:

  • 亲爱的瑞克,谢谢您的回答。不幸的是,打开的任务窗格甚至不是已定义的任务窗格,而是在 SourceLocation 中定义的网页。所以清单的 VersionOverrides 部分被完全忽略。换句话说,Office.AutoShowTaskpaneWithDocument id 被完全忽略,文档只打开一个定义为在 Word 不支持命令加载项时的备份的 URL。
  • 您的 Word 版本和版本是什么?
  • 我不确定出了什么问题,但我设法解决了它。我没有调整本地客户端插件生成的 OOXML,而是使用了服务器端插件生成的 OOXML。不清楚为什么这会奏效。非常感谢你帮助我。
猜你喜欢
  • 1970-01-01
  • 2022-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多