首页 文章

自动打开任务窗格,打开sourcelocation url,而不是使用Office.AutoShowTaskpaneWithDocument id的任务窗格

提问于
浏览
0

Context

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

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

The Goal

理想情况下,我想创建一些文档,当用户打开时,会自动从此加载项打开某个任务窗格 . 文档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引用了manifest和Office.AutoShowTaskpaneWithDocument id,因此它将打开正确的taskpane . 这是通过添加以下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>

The Problem

该文档确实打开了一个任务窗格,但它在Taskpane Mode集成中打开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标记 .

任何帮助将不胜感激!

EDIT 我设法解决了这个问题,但我不确定导致解决方案的原因 . 我没有调整由本地客户端加载项生成的OOXML,而是使用了由服务器端加载项生成的OOXML .

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

Appendix 1: Entire manifest, urls and names are changed.

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

1 回答

  • 1

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

相关问题