如何设置Excel任务窗格加载项启动时默认隐藏?
禁用Excel任务窗格加载项自动打开的方法
问题描述
我正在使用React和Excel JavaScript API开发Excel任务窗格加载项,目前遇到的问题是:打开新Excel工作簿或加载项初始化时,任务窗格会默认显示。查阅多篇介绍如何自动打开任务窗格的文章,但未找到禁用其随工作簿自动打开的方法,请问如何实现打开新工作簿或安装加载项时,禁用任务窗格自动打开?
环境信息
Excel office 365 Windows 10 pro
Manifest.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>
解决方案
要禁用任务窗格自动打开,只需修改Manifest.xml中的以下配置:
移除默认任务窗格启动配置:找到
<DefaultSettings>节点,删除其中的<SourceLocation>标签。修改后的节点如下:<DefaultSettings> </DefaultSettings>这个标签定义了加载项初始化时默认打开的任务窗格地址,移除后Excel就不会自动弹出任务窗格。
保持功能区触发逻辑:你的Manifest中已经配置了功能区按钮(
LoginControl),点击按钮会通过ShowTaskpane动作打开任务窗格,这部分无需修改,用户仍可通过主动点击按钮打开任务窗格。
最后,修改Manifest后需要重新安装加载项,确保新配置生效。
内容的提问来源于stack exchange,提问作者vibhor Gupta
相关产品推荐
相关产品推荐

