0

Task Pane当我决定如果可能的话我更愿意使用它时,我终于得到了我的“对话”代码来收集简单的用户输入。我一直在研究多个任务窗格,并让它以两种不同的方式工作。但是,我正在使用 aShared Runtime并阅读以下内容。

MS Docs的以下引用说明了这一点:

如果您计划使用共享运行时,请勿将加载项设计为使用多个任务窗格。共享运行时仅支持使用一个任务窗格。请注意,任何没有 a 的任务窗格<TaskpaneID> 都被视为不同的任务窗格。

有没有利用多个任务窗格的最佳方法,可以吗?这是否意味着多个 OPEN 任务窗格和/或具有不同的任务窗格<TaskpaneID>?我不需要taskpanes同时运行两个,它们只是用于收集用户输入和运行子程序。我还没有对我的设置进行广泛的测试,但到目前为止,我可以用不同的 HTML 文件很好地打开任务窗格。

我的第一次尝试(工作)是TaskPane在 XML 中定义一个带有脚本的脚本,该脚本将之后加载的页面重定向taskpane.html到所需的页面。

我通过从加载项taskpane.js调用的以下函数执行此操作:command

Office.onReady((info) => {

});

function Do_OpenURLInTaskPane(URL, event) {
    console.log("URL:"+URL)
    location.href = URL
    event.completed();
    return true;
};


function getGlobal() {
    return typeof self !== "undefined"
        ? self
        : typeof window !== "undefined"
            ? window
            : typeof global !== "undefined"
                ? global
                : undefined;
}

var g = getGlobal();

//Add-In Commands
g.Do_OpenURLInTaskPane = Do_OpenURLInTaskPane;

我的第二次尝试是在manifest.xml

我所做的是将原始taskpane.html定义保留在以下内容下:

<FunctionFile resid="Taskpane.Url"/>

<SourceLocation resid="Taskpane.Url"/>

<Runtimes>
  <Runtime resid="Taskpane.Url" lifetime="long" />
</Runtimes>

然后我删除了调用它的按钮并定义了两个新按钮来打开所需的 URL,如下所示:

             <Control xsi:type="Button" id="FirstTPBT">
                  <Label resid="TaskpaneButton.Label"/>
                  <Supertip>
                      <Title resid="TaskpaneButton.Label"/>
                      <Description resid="TaskpaneButton.Tooltip"/>
                  </Supertip>
                  <Icon>
                      <bt:Image size="16" resid="Icon.16x16"/>
                      <bt:Image size="32" resid="Icon.32x32"/>
                      <bt:Image size="80" resid="Icon.80x80"/>
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                      <TaskpaneId>ButtonId1</TaskpaneId>
                      <SourceLocation resid="FirstTP.Url"/>
                  </Action>
              </Control>
              <Control xsi:type="Button" id="SecondTPBY">
                  <Label resid="TaskpaneButton.Label"/>
                  <Supertip>
                      <Title resid="TaskpaneButton.Label"/>
                      <Description resid="TaskpaneButton.Tooltip"/>
                  </Supertip>
                  <Icon>
                      <bt:Image size="16" resid="Icon.16x16"/>
                      <bt:Image size="32" resid="Icon.32x32"/>
                      <bt:Image size="80" resid="Icon.80x80"/>
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                      <TaskpaneId>ButtonId1</TaskpaneId>
                      <SourceLocation resid="SecondTP.Url"/>
                  </Action>
              </Control>

基本上,我不希望dialog在需要收集用户输入时使用,而是使用单独定制的taskpane,然后commands在不需要输入时使用。

寻找有关这些选项的反馈和/或为什么选择一种方法而不是另一种方法或另一种方法的原因。

4

1 回答 1

1

我有同样的问题,现在我正在为 Excel 编写 Office 插件(本地和非共享运行时),而且我正在使用 React 框架。我尝试了两种不同的方法来执行此操作:

  1. 使用 React-Router-Dom,我尝试安装这个包来做一个反应路由,但是 Office 插件阻止了浏览器中的一些功能并且这种类型的解决方案不起作用;
  2. 使用 html 的 Window 元素,首先我创建了一个 html 模板 (.hbs),我将其命名为“taskpane.html”,并将所有内容从 taskpane.html 复制到 taskpane.hbs。我使用这个模板是因为在这种情况下我可以在 html 文件中使用一些参数。html文件的主要部分是这样的:
  window.SOME_PARAMS = {
    ENTRYPOINT: "{{htmlWebpackPlugin.options.entryPoint}}",
  };

之后,我修改了 webpack.config.js,为每个任务窗格添加了不同的 entry_point

taskpane1: [
  "./path/of/specific/entrypointJS/entrypoint.js"
]

最后,我使用 html 中定义的参数在不同的任务窗格之间导航

switch(window.SOME_PARAMS.ENTRYPOINT) {
  case 'Taskpane1':
    return (
      ...
    );
      break;
  case 'Taskpane2':
    return(
      ...
    );
  break;
  case 'TaskPane3':
    return(
     ...
    );
    break;
}

您的清单文件是正确的,但您必须区分任务窗格按钮的 url

    <bt:Url id="Taskpane_1.Url" DefaultValue="https://localhost:3000/taskpane-1.html"/>
    <bt:Url id="Taskpane_2.Url" DefaultValue="https://localhost:3000/taskpane-2.html"/>
    <bt:Url id="Taskpane_2.Url" DefaultValue="https://localhost:3000/taskpane-3.html"/>
于 2022-02-16T14:59:52.947 回答