打开 Excel 工作簿和在 Excel 中初始化加载项时,默认情况下在 Microsoft Office 加载项中隐藏任务窗格

问题描述 投票:0回答:2

我正在使用 React 和 Excel JavaScript API 制作一个 Excel 任务窗格插件。我面临的问题是,当我打开一个新的 Excel 工作簿或在 excel 中初始化插件时,默认情况下插件任务窗格是可见的。我浏览了多篇文章,其中介绍了如何自动打开任务窗格,但没有一篇文章描述了如何禁用在工作簿上打开的任务窗格。

那么,当我们打开一个新的工作簿或安装插件时,如何禁用自动打开任务窗格。

Excel office 365
Windows 10 pro

清单.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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">
  <Id>81d7e91a-c8e6-454f-806a-9b84cf3e7dd5</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>Contoso</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="Add-in"/>
  <Description DefaultValue="A template to get started."/>
  <IconUrl DefaultValue="https://localhost:3000/assets/login_32.png"/>
  <HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/login.png"/>
  <SupportUrl DefaultValue="https://www.contoso.com/help"/>
  <AppDomains>
    <AppDomain>https://www.contoso.com</AppDomain>
  </AppDomains>
  <Hosts>
    <Host Name="Workbook"/>
  </Hosts>
  <Requirements>
    <Sets DefaultMinVersion="1.1">
      <Set Name="SharedRuntime" MinVersion="1.1"/>
    </Sets>
  </Requirements>
  <DefaultSettings>
    <SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>
  </DefaultSettings>
  <Permissions>ReadWriteDocument</Permissions>
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
    <Hosts>
      <Host xsi:type="Workbook">
        <Runtimes>
          <Runtime resid="Taskpane.Url" lifetime="long" />
        </Runtimes>
        <DesktopFormFactor>
          <GetStarted>
            <Title resid="GetStarted.Title"/>
            <Description resid="GetStarted.Description"/>
            <LearnMoreUrl resid="GetStarted.LearnMoreUrl"/>
          </GetStarted>
          <ExtensionPoint xsi:type="PrimaryCommandSurface">
            <CustomTab id="CustomTab">
              <Group id="AuthGroup">

                <Label resid="AuthGroupNameLabel" />
                <Icon>
                  <bt:Image size="16" resid="Group1LoginIcon16" />
                  <bt:Image size="32" resid="Group1LoginIcon32" />
                  <bt:Image size="80" resid="Group1LoginIcon80" />
                </Icon>

                <Control xsi:type="Button" id="Contoso.LoginControl">
                  <Label resid="LoginButtonLabel" />
                  <Supertip>
                    <Title resid="LoginButtonToolTipTitle" />
                    <Description resid="LoginButtonToolTipDescription" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="Group1LoginIcon16" />
                    <bt:Image size="32" resid="Group1LoginIcon32" />
                    <bt:Image size="80" resid="Group1LoginIcon80" />
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                    <TaskpaneId>LoginPanelId</TaskpaneId>
                    <SourceLocation resid="LoginTaskPaneUrl" />
                    <Title resid="LoginTaskPaneTitle" />
                  </Action>
                </Control>
              </Group>
              <Label resid="ribbonNameLabel" />
            </CustomTab>
          </ExtensionPoint>
        </DesktopFormFactor>
      </Host>
    </Hosts>
    <Resources>
      <bt:Images>
        <bt:Image id="Group1LoginIcon16" DefaultValue="https://localhost:3000/assets/login_16.png"/>
        <bt:Image id="Group1LoginIcon32" DefaultValue="https://localhost:3000/assets/login_32.png"/>
        <bt:Image id="Group1LoginIcon80" DefaultValue="https://localhost:3000/assets/login.png"/>
      </bt:Images>
      <bt:Urls>
        <bt:Url id="GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812"/>
        <bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html"/>
        <bt:Url id="LoginTaskPaneUrl" DefaultValue="https://localhost:3000/taskpane.html"/>
        <bt:Url id="Functions.Script.Url" DefaultValue="https://localhost:3000/public/functions.js"/>
        <bt:Url id="Functions.Metadata.Url" DefaultValue="https://localhost:3000/public/functions.json"/>
        <bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html"/>
      </bt:Urls>
      <bt:ShortStrings>
        <bt:String id="GetStarted.Title" DefaultValue="Get started with your sample add-in!"/>
        <bt:String id="ribbonNameLabel" DefaultValue="Add-in"/>
        <bt:String id="AuthGroupNameLabel" DefaultValue="Auth"/>
        <bt:String id="LoginButtonLabel" DefaultValue="Login" />
        <bt:String id="LoginTaskPaneTitle" DefaultValue="Login" />
        <bt:String id="LoginButtonToolTipTitle" DefaultValue="Tooltip Title" />
      </bt:ShortStrings>
      <bt:LongStrings>
        <bt:String id="GetStarted.Description" DefaultValue="Welcome to Add-in"/>
        <bt:String id="LoginButtonToolTipDescription" DefaultValue="Tooltip Description" />
      </bt:LongStrings>
    </Resources>
  </VersionOverrides>
</OfficeApp>
office365 office-js office-addins excel-addins excel-web-addins
2个回答
0
投票

清单文件中的以下部分负责打开带有文档的任务窗格:

<Action xsi:type="ShowTaskpane">
   <TaskpaneId>LoginPanelId</TaskpaneId>
   <SourceLocation resid="LoginTaskPaneUrl" />
   <Title resid="LoginTaskPaneTitle" />
</Action>

此外,在您的加载项代码中,您可以标记文档以打开任务窗格:

Office.context.document.settings.set("Office.AutoShowTaskpaneWithDocument", true);
Office.context.document.settings.saveAsync();

使用Office.js

settings.set
方法将
Office.AutoShowTaskpaneWithDocument
设置为
true
。或者作为可能的替代方案,您可以为此使用 Open XML SDK。

Automatically open a task pane with a document文章中阅读更多相关信息。

如您所见,应该在两个方面设置配置 - 清单文件和文档。您需要将其中一侧配置为不显示任务窗格。删除数据的位置由您决定。但是没有可以动态配置的标志(如回调)。您可以在 Tech Community 上发布或投票支持现有功能请求,Office 开发团队在规划过程中会考虑这些请求。


0
投票

用 manifest.xml 中的 ExecuteFunction 操作替换 ShowTaskPane

<Action xsi:type="ExecuteFunction">
   <FunctionName>btnopentaskpane</FunctionName>
</Action>

在 commands.ts 文件中添加了 btnOpenTaskpane :

async function btnOpenTaskpane(event) {
  console.log("Open task pane button pressed");
  Office.addin.showAsTaskpane()
  event.completed();
}
Office.actions.associate("btnOpenTaskpane", btnOpenTaskpane);

为了更好的理解我们可以参考github repo微软提供的例子

© www.soinside.com 2019 - 2024. All rights reserved.