【问题标题】:Auto-opening side-loaded taskpane自动打开侧载任务窗格
【发布时间】:2019-06-02 10:06:53
【问题描述】:

是否可以自动打开处于开发者模式的插件?

根据documentation

您指定自动打开的窗格只有在以下情况下才会打开 外接程序已安装在用户的设备上。如果用户这样做 打开文档时没有安装加载项,自动打开 功能将不起作用,设置将被忽略。如果你也 要求加载项与您需要设置的文档一起分发 可见性属性为 1;这只能使用 OpenXML 来完成,一个 本文稍后会提供示例。

特别是,我尝试自动打开的文件是基于 office-generator 的文件,只进行了一次修改:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <we:webextension xmlns:we="http://schemas.microsoft.com/office/webextensions/webextension/2010/11" id="{acbc717b-5139-428a-9089-e9d6d7d8affc}">
  <we:reference id="acbc717b-5139-428a-9089-e9d6d7d8affc" version="1.0.0.0" store="developer" storeType="Registry"/>
  <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>

加上&lt;we:property name="Office.AutoShowTaskpaneWithDocument" value="true"/&gt;

并通过如下修改manifest.xml

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

问题:

预计会有一个自动打开的任务窗格。

自动打开的任务窗格有一个错误,指出we can't find the task pane to open。另一方面,单击功能区可以让任务窗格正常打开,与损坏的自动打开的任务窗格并排打开,如下图所示:

【问题讨论】:

  • 请使用 Fiddler 工具比较自动打开窗格和按下按钮时的 HTTP 请求/响应。
  • @RickKirkham Seems to be attempting to connect to office instead of localhost.。箭头之后是当我单击按钮打开第二个任务窗格时。
  • @RickKirkham 更具体地说,它只尝试连接到:GET /ocs/docs/recent?rs=en-US&amp;apps=Word&amp;show=100 HTTP/1.1,然后是GET /ocs/locations/recent?rs=en-US&amp;apps=Word&amp;show=100 HTTP/1.1,最后是POST /rs/RoamingSoapService.svc HTTP/1.1。在我打开另一个任务窗格之前,它永远不会尝试访问 localhost。

标签: office-js office-js-helpers


【解决方案1】:

Microsoft Word 中有一个隐藏状态,即使在重新启动后仍然存在。要重现错误,您几乎需要新计算机

让我解释一下我是如何在... 1 周后让它工作的。

首先从 office-js 生成器开始。

yo office,为此我选择了打字稿。

修改src/taskpane/taskpane.ts如下:

export async function run() {
  return Word.run(async context => {
    /**
     * Insert your Word code here
     */

    // insert a paragraph at the end of the document.
    const paragraph = context.document.body.insertParagraph("Hello World", Word.InsertLocation.end);

    // change the paragraph color to blue.
    paragraph.font.color = "blue";

    // Add these two lines
    Office.context.document.settings.set("Office.AutoShowTaskpaneWithDocument", true);
    Office.context.document.settings.saveAsync();
    // Technically should wait, but doesn't matter.

    await context.sync();
  });

修改 manifest.xml 如下: 将ButtonId1 替换为Office.AutoShowTaskpaneWithDocument

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

正常启动项目。 npm run start

点击运行按钮触发自动打开文件的创建。

将文件保存在某处。

重新打开它以验证它是否有效。有趣的是,当我单击显示任务窗格按钮时,它创建了一个相同的任务窗格。这是一个错误,但对我有用。毕竟是为了测试。

证明文件的问题确实是隐藏状态: 在新计算机上克隆 repo,npm run start,复制文件。

运行文件,你会遇到和我原来的帖子一样的问题。

【讨论】:

  • 谢谢...这个帖子很有用...您知道是否可以在localhost中测试自动打开?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-24
  • 1970-01-01
  • 1970-01-01
  • 2017-01-15
  • 2016-10-27
相关资源
最近更新 更多