【问题标题】:customtab and contextcellmenu : button activation/desactivationcustomtab 和 contextcellmenu :按钮激活/取消激活
【发布时间】:2021-03-30 18:49:05
【问题描述】:

我有一个 Excel Web 插件可以正常工作:

一个包含五个控制按钮的自定义选项卡 一个菜单控件添加到 contextmenucell..

但是,激活和停用按钮仍然存在一些困难。

'false'/Enabled'>' XML 指令引发«无效子元素»消息

【问题讨论】:

  • 显示 ExtensionPoint 及其子元素的 XML。

标签: excel xml button office-js contextmenu


【解决方案1】:
<OfficeApp ...>
  ...
  <VersionOverrides ...>
    ...
    <Hosts>
      <Host ...>
        ...
        <DesktopFormFactor>
          <ExtensionPoint ...>
            <CustomTab ...>
              ...
              <Group ...>
                ...
                <Control ... id="MyButton">
                  ...
                  <Action ...>
                  <Enabled>false</Enabled>
...
</OfficeApp>

【讨论】:

    【解决方案2】:

    @RickKirkham`

           <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"
           xsi:type="TaskPaneApp">
           <Id>7F8D6A98-CA41-474C-9DA2-D0A511EC822F</Id>
           <Version>1.0.0.0</Version>
           <ProviderName>[Provider name]</ProviderName>
           <DefaultLocale>en-US</DefaultLocale>
           <DisplayName DefaultValue="appx" />
           <Description DefaultValue="appx description."/>
    <!-- Icon for your add-in. Used on installation screens and the add-ins dialog. -->
    <!--<IconUrl DefaultValue="https://appcommandicons.blob.core.windows.net/images/taskpane_32x.png" />-->
           <IconUrl DefaultValue="~remoteAppUrl/Images/icone appx.png" />
           <Hosts>
              <Host Name="Workbook" />
           </Hosts>
          <Requirements>
          <Sets DefaultMinVersion="1.3">
            <Set Name="SharedRuntime" MinVersion="1.1"/>
            <Set Name="ExcelApi" MinVersion="1.3"/>
            <Set Name="DialogApi" MinVersion="1.1"/>
            <Set Name ="AddinCommands" MinVersion ="1.1"/>
        </Sets>
        </Requirements>
        <DefaultSettings>
        <SourceLocation DefaultValue="~remoteAppUrl/App/Home/Home.html" />
        </DefaultSettings>
        <Permissions>ReadWriteDocument</Permissions>
    <!-- Begin Add-in Commands Mode integration. -->
          <VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
        <!-- Explications languages : https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-owemxml/ef7df550-1528-4efd-b3b8-8b52ad2a8e80-->
        <!-- The Hosts node is required. -->
        <Hosts>
            <!-- Each host can have a different set of commands. -->
            <!-- Excel host is Workbook, Word host is Document, and PowerPoint host is Presentation. -->
            <!-- Make sure the hosts you override match the hosts declared in the top section of the manifest. -->
            <Host xsi:type="Workbook">
                <!-- Form factor. Currently only DesktopFormFactor is supported. -->
                <DesktopFormFactor>
                    <!--"This code enables a customizable message to be displayed when the add-in is loaded successfully upon individual install."-->
                    <GetStarted>
                        <!--Title of the Getting Started callout. resid points to a ShortString resource -->
                        <Title resid="Contoso.GetStarted.Title"/>
                        <!-- Description of the Getting Started callout. resid points to a LongString resource -->
                        <Description resid="Contoso.GetStarted.Description"/>
                        <!-- Point to a url resource which details how the add-in should be used. -->
                        <LearnMoreUrl resid="Contoso.GetStarted.LearnMoreUrl"/>
                    </GetStarted>
                    <FunctionFile resid="Contoso.FunctionFile.Url" />
                    <!-- PrimaryCommandSurface is the main Office Ribbon. -->
                    <ExtensionPoint xsi:type="PrimaryCommandSurface">
                        <!-- Use OfficeTab to extend an existing Tab. Use CustomTab to create a new tab. -->
                        <!---->
                        <!--<OfficeTab id= "TabHome">-->
                        <CustomTab id="Contoso.Group1Label">
                            <!--<Label resid="Contoso.Group1Label"/ >-->
                            <Group id="Contoso.Group2Label">
                                <Label resid="Contoso.Group2Label" />
                                <Icon>
                                    <bt:Image size="16" resid="Contoso.tpicon_16x16" />
                                    <bt:Image size="32" resid="Contoso.tpicon_32x32" />
                                    <bt:Image size="80" resid="Contoso.tpicon_80x80" />
                                </Icon>
                                <Control xsi:type="Button" id="residLabel" >
                                    <Label resid="residLabel" />
                                    <Supertip>
                                        <Title resid="Contoso.TaskpaneButton.Label3"  />
                                        <Description resid="Contoso.TaskpaneButton.Lancer"  />
                                    </Supertip>
                                    <Icon>
                                        <bt:Image size="16" resid="Contoso.Ouvrir_16x16" />
                                        <bt:Image size="20" resid="Contoso.Ouvrir_20x20" />
                                        <bt:Image size="24" resid="Contoso.Ouvrir_24x24" />
                                        <bt:Image size="32" resid="Contoso.Ouvrir_32x32" />
                                        <bt:Image size="40" resid="Contoso.Ouvrir_40x40" />
                                        <bt:Image size="80" resid="Contoso.Ouvrir_80x80" />
                                    </Icon>
                                    <Action xsi:type="ExecuteFunction">
                                        <FunctionName>action1</FunctionName>
                                    </Action>
                                </Control>
    
                                <Control xsi:type="Button" id="residLabel9" >
                                    <Label resid="residLabel9" />
                                    <Supertip>
                                        <Title resid="Contoso.TaskpaneButton.Label4"  />
                                        <Description resid="Contoso.TaskpaneButton.Suspendre"  />
                                    </Supertip>
                                    <Icon>
                                        <bt:Image size="16" resid="Contoso.Yo$_16x16" />
                                        <bt:Image size="20" resid="Contoso.Yo$_20x20" />
                                        <bt:Image size="24" resid="Contoso.Yo$_24x24" />
                                        <bt:Image size="32" resid="Contoso.Yo$_32x32" />
                                        <bt:Image size="40" resid="Contoso.Yo$_40x40" />
                                        <bt:Image size="80" resid="Contoso.Yo$_80x80" />
                                    </Icon>
                                    <Action xsi:type="ExecuteFunction">
                                        <FunctionName>action2</FunctionName>
                                    </Action>
                                    <!--<Enabled>false</Enabled>-->
                                </Control>
                            </Group>
                            <Group id="Contoso.Group3">
                                <Label resid="Contoso.Group3Label" />
                                <Icon>
                                    <bt:Image size="16" resid="Contoso.Réinit_16x16" />
                                    <bt:Image size="20" resid="Contoso.Réinit_20x20" />
                                    <bt:Image size="24" resid="Contoso.Réinit_24x24" />
                                    <bt:Image size="32" resid="Contoso.Réinit_32x32" />
                                    <bt:Image size="40" resid="Contoso.Réinit_40x40" />
                                    <bt:Image size="80" resid="Contoso.Réinit_80x80" />
                                </Icon>
                                <Control xsi:type="Button" id="residLabel6" >
                                    <Label resid="residLabel6" />
                                    <Supertip>
                                        <Title resid="residLabel6"  />
                                        <Description resid="Contoso.TaskpaneButton.Réinit"  />
                                    </Supertip>
                                    <Icon>
                                        <bt:Image size="16" resid="Contoso.Réinit_16x16" />
                                        <bt:Image size="20" resid="Contoso.Réinit_20x20" />
                                        <bt:Image size="24" resid="Contoso.Réinit_24x24" />
                                        <bt:Image size="32" resid="Contoso.Réinit_32x32" />
                                        <bt:Image size="40" resid="Contoso.Réinit_40x40" />
                                        <bt:Image size="80" resid="Contoso.Réinit_80x80" />
                                    </Icon>
                                    <Action xsi:type="ExecuteFunction">
                                        <FunctionName>action3</FunctionName>
                                    </Action>
                                </Control>
                                <Control xsi:type="Button" id="residLabel7" >
                                    <Label resid="residLabel7" />
                                    <Supertip>
                                        <Title resid="residLabel7"  />
                                        <Description resid="Contoso.TaskpaneButton.Sauver"  />
                                    </Supertip>
                                    <Icon>
                                        <bt:Image size="16" resid="Contoso.Sauver_16x16" />
                                        <bt:Image size="20" resid="Contoso.Sauver_20x20" />
                                        <bt:Image size="24" resid="Contoso.Sauver_24x24" />
                                        <bt:Image size="32" resid="Contoso.Sauver_32x32" />
                                        <bt:Image size="40" resid="Contoso.Sauver_40x40" />
                                        <bt:Image size="80" resid="Contoso.Sauver_80x80" />
                                    </Icon>
                                    <Action xsi:type="ExecuteFunction">
                                        <FunctionName>actio4</FunctionName>
                                    </Action>
                                </Control>
                            </Group>
                            <Label resid="Contoso.Group1Label" />
                        </CustomTab>
                        <!--<InsertAfter>TabReview</InsertAfter>-->
                    </ExtensionPoint>
                    <ExtensionPoint xsi:type="ContextMenu">
                        <OfficeMenu id="ContextMenuCell">
    
                            <Control xsi:type="Menu" id="Autre2" >
                                <Label resid="Contoso.TaskpaneButton.Label2" />
                                <Supertip>
                                    <Title resid="Contoso.TaskpaneButton.Label2"  />
                                    <Description resid="Contoso.TaskpaneButton.Tooltip"  />
                                </Supertip>
                                <Icon>
                                    <bt:Image size="16" resid="Contoso.No$_16x16" />
                                    <bt:Image size="20" resid="Contoso.No$_20x20" />
                                    <bt:Image size="24" resid="Contoso.No$_24x24" />
                                    <bt:Image size="32" resid="Contoso.No$_32x32" />
                                    <bt:Image size="40" resid="Contoso.No$_40x40" />
                                    <bt:Image size="80" resid="Contoso.No$_80x80" />
                                </Icon>
                                <Items>
                                    <Item id="couper">
                                        <Label resid="residLabel5"/>
                                        <Supertip>
                                            <Title resid="residLabel" />
                                            <Description resid="residToolTip" />
                                        </Supertip>
                                        <Icon>
                                            <bt:Image size="16" resid="Contoso.couper_16x16" />
                                            <bt:Image size="20" resid="Contoso.couper_20x20" />
                                            <bt:Image size="24" resid="Contoso.couper_24x24" />
                                            <bt:Image size="32" resid="Contoso.couper_32x32" />
                                            <bt:Image size="40" resid="Contoso.couper_40x40" />
                                            <bt:Image size="80" resid="Contoso.couper_80x80" />
                                        </Icon>
                                        <Action xsi:type="ExecuteFunction">
                                            <FunctionName>action5</FunctionName>
                                        </Action>
                                    </Item>
                                    <Item id="copier">
                                        <Label resid="residLabel1"/>
                                        <Supertip>
                                            <Title resid="residLabel" />
                                            <Description resid="residToolTip" />
                                        </Supertip>
                                        <Icon>
                                            <bt:Image size="16" resid="Contoso.Copier_16x16" />
                                            <bt:Image size="20" resid="Contoso.Copier_20x20" />
                                            <bt:Image size="24" resid="Contoso.Copier_24x24" />
                                            <bt:Image size="32" resid="Contoso.Copier_32x32" />
                                            <bt:Image size="40" resid="Contoso.Copier_40x40" />
                                            <bt:Image size="80" resid="Contoso.Copier_80x80" />
                                        </Icon>
                                        <Action xsi:type="ExecuteFunction">
                                            <FunctionName>action6</FunctionName>
                                        </Action>
                                    </Item>
                                    <Item id="coller">
                                        <Label resid="residLabel2"/>
                                        <Supertip>
                                            <Title resid="residLabel" />
                                            <Description resid="residToolTip" />
                                        </Supertip>
                                        <Icon>
                                            <bt:Image size="16" resid="Contoso.Coller_16x16" />
                                            <bt:Image size="20" resid="Contoso.Coller_20x20" />
                                            <bt:Image size="24" resid="Contoso.Coller_24x24" />
                                            <bt:Image size="32" resid="Contoso.Coller_32x32" />
                                            <bt:Image size="40" resid="Contoso.Coller_40x40" />
                                            <bt:Image size="80" resid="Contoso.Coller_80x80" />
                                        </Icon>
                                        <Action xsi:type="ExecuteFunction">
                                            <FunctionName>action7</FunctionName>
                                        </Action>
                                    </Item>
                                    <Item id="supprimer">
                                        <Label resid="residLabel4"/>
                                        <Supertip>
                                            <Title resid="residLabel" />
                                            <Description resid="residToolTip" />
                                        </Supertip>
                                        <Icon>
                                            <bt:Image size="16" resid="Contoso.Supprimer_16x16" />
                                            <bt:Image size="20" resid="Contoso.Supprimer_20x20" />
                                            <bt:Image size="24" resid="Contoso.Supprimer_24x24" />
                                            <bt:Image size="32" resid="Contoso.Supprimer_32x32" />
                                            <bt:Image size="40" resid="Contoso.Supprimer_40x40" />
                                            <bt:Image size="80" resid="Contoso.Supprimer_80x80" />
                                        </Icon>
                                        <Action xsi:type="ExecuteFunction">
                                            <FunctionName>action8</FunctionName>
                                        </Action>
                                    </Item>                                 
                                </Items>
                            </Control>
                        </OfficeMenu>
                    </ExtensionPoint>
                </DesktopFormFactor>
            </Host>
        </Hosts>
    </VersionOverrides>
    

    【讨论】:

      【解决方案3】:

      您需要在控件元素内粘贴&lt;Enabled&gt;标签:

      <Control xsi:type="Button" id="residLabel6" >
        <Label resid="residLabel6" />
          <Supertip>
            <Title resid="residLabel6"  />
            <Description resid="Contoso.TaskpaneButton.Réinit"  />
          </Supertip>
          <Icon>
            <bt:Image size="16" resid="Contoso.Réinit_16x16" />
            <bt:Image size="20" resid="Contoso.Réinit_20x20" />
            <bt:Image size="24" resid="Contoso.Réinit_24x24" />
            <bt:Image size="32" resid="Contoso.Réinit_32x32" />
            <bt:Image size="40" resid="Contoso.Réinit_40x40" />
            <bt:Image size="80" resid="Contoso.Réinit_80x80" />
          </Icon>
          <Action xsi:type="ExecuteFunction">
            <FunctionName>action3</FunctionName>
          </Action>
          <Enabled>false</Enabled>
      </Control>
      

      默认情况下,任何加载项命令都会在 Office 应用程序启动时启用。如果您希望在 Office 应用程序启动时禁用自定义按钮或菜单项,请在清单中指定。只需在控件声明中的Action 元素下方(不在内部)添加一个Enabled 元素(值为false)。

      Enable and Disable Add-in Commands 文章中了解更多信息。

      【讨论】:

      • 这正是 Xml 通过抛出这个“无效的子元素”消息而拒绝的。查看我发送的 Xml 页面
      • 作为测试,我尝试使用来自 Visual Studio 2019 的新 Excel Web 补充,结果相同: 仍然是无效的子元素。有什么建议吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-30
      • 1970-01-01
      • 2016-03-15
      • 1970-01-01
      • 2021-02-03
      相关资源
      最近更新 更多