office365office-jsoffice-addinsexcel-addinsexcel-web-addins

Hide Task pane in microsoft office add-in by default when Excel workbook is opened and when add-in is initialized in Excel


I am making a Excel task pane add-in using React and the Excel JavaScript API. The issue I am facing is the add-in task pane is visible by default when I open a new Excel worbook or when addin is initialized in excel. I have gone through multiple articles which says how to open task pane automatically but none describes how to disable the task pane opening on workbook.

So how can I disable automatic opening of task pane when we open a new workbook or when we install the addin.

Excel office 365
Windows 10 pro

Manifiest.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>

Solution

  • Replaced ShowTaskPane with ExecuteFunction action in manifest.xml

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

    Added btnOpenTaskpane in commands.ts file :

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

    For better understanding we can refer github repo examples provided by microsoft