自动打开侧载任务面板 [英] Auto-opening side-loaded taskpane

查看:51
本文介绍了自动打开侧载任务面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

根据

解决方案

Microsoft Word 中某处存在隐藏状态,即使重新启动后该状态仍然存在.要重现该错误,您几乎需要新计算机.

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

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

yo office,我选择了打字稿.

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

导出异步函数 run() {返回 Word.run(异步上下文 => {/*** 在此处插入您的 Word 代码*///在文档末尾插入一个段落.const 段落 = context.document.body.insertParagraph("Hello World", Word.InsertLocation.end);//将段落颜色更改为蓝色.段落字体颜色=蓝色";//添加这两行Office.context.document.settings.set("Office.AutoShowTaskpaneWithDocument", true);Office.context.document.settings.saveAsync();//技术上应该等待,但没关系.等待 context.sync();});

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

<TaskpaneId>Office.AutoShowTaskpaneWithDocument</TaskpaneId><SourceLocation resid="Taskpane.Url"/></动作>

照常启动项目.npm 运行开始

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

将文件保存在某处.

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

证明文件的问题确实是隐藏状态:在新计算机上克隆存储库,npm run start,将文件复制过来.

运行该文件,您将遇到与我在原始帖子中遇到的相同问题.

Is it possible to auto-open plugins that are in developer mode?

According to documentation

The pane that you designate to open automatically will only open if the add-in is already installed on the user's device. If the user does not have the add-in installed when they open a document, the autoopen feature will not work and the setting will be ignored. If you also require the add-in to be distributed with the document you need to set the visibility property to 1; this can only be done using OpenXML, an example is provided later in this article.

In particular, the file i'm attempting to auto-open is what based off office-generator with a single modification:

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

with the addition of <we:property name="Office.AutoShowTaskpaneWithDocument" value="true"/>

and by modifying manifest.xml as follows:

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

Problem:

It is expected that there would be one taskpane which would be opened automatically.

The task pane that was opened automatically has an error which states that we can't find the task pane to open. On the other hand, clicking on the ribbon allows the task pane to open as per normal, side by side with the broken auto-opened task pane as shown in the image below:

解决方案

There's a hidden-state in Microsoft Word somewhere, that persists even after restarts. To reproduce the error you pretty much need a new computer.

Let me explain how i got it working after... 1 week.

First start with office-js generator.

yo office, for which i selected typescript.

Modify src/taskpane/taskpane.ts as follows:

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();
  });

Modify manifest.xml as follows: Replace ButtonId1 with Office.AutoShowTaskpaneWithDocument

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

Launch the project as per normal. npm run start

Click the run button to trigger the creation of the auto-open file.

Save the file somewhere.

Re-open it to verify that it works. Funnily enough, it created an identical taskpanes when i clicked on the show taskpane button. This is a bug but works for me. It's for testing purposes after all.

To prove that the file's problem is indeed a hidden state: Clone the repo on a new computer, npm run start, copy the file over.

Run the file and you will get the same problem as i got in my original post.

这篇关于自动打开侧载任务面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆