Word中的上下文菜单

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

为Word加载项创建清单。我试图将两个菜单项放在ContextMenuText上。我在这里遵循指南:https://docs.microsoft.com/en-us/office/dev/add-ins/reference/manifest/control#menu-dropdown-button-controls。这是我了解的地方:

与PrimaryCommandSurface或ContextMenu扩展点一起使用时,菜单控件定义:

  • 根级菜单项。
  • 子菜单项列表

[我读到的所有内容都表明这是可能的,并且当我运行NPM VALIDATE时,它告诉我清单是有效的。但是,当我尝试使用NPM START进行侧面加载时,任务窗格会出现黄色警告,表明未加载清单。另外,当我尝试在Word Online中进行旁加载时,它告诉我清单无效。

如果我仅将单个顶级控件定义为按钮,则效果很好。但是我确实需要上下文菜单上的两个项目。

这是我清单的相关部分:

<!--CONTEXT MENU-->
<ExtensionPoint xsi:type="ContextMenu">
<OfficeMenu id="ContextMenuText">
  <Control xsi:type="Menu" id="myMenuId">
    <Label resid="ContextMenu.Label" />
    <Supertip>
        <Title resid="ContextMenu.Label" />
        <Description resid="ContextMenu.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>    
    <Items>
      <!--FIRST CONTEXT MENU BUTTON-->
      <Item id="firstCtxMenuId">
        <Label resid="FirstButton.Label"/>
        <Supertip>
          <Title resid="FirstButton.Label"/>
          <Description resid="FirstButton.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="ExecuteFunction">
          <FunctionName>doThing1</FunctionName>
        </Action>
      </Item>
      <!--SECOND CONTEXT MENU BUTTON-->
      <Item id="secondCtxMenuId"> -->
        <Label resid="SecondButton.Label"/>
        <Supertip>
          <Title resid="SecondButton.Label"/>
          <Description resid="SecondButton.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="ExecuteFunction">
          <FunctionName>doThing2</FunctionName>
        </Action>
      </Item>
    </Items>
  </Control>
</OfficeMenu>

我的清单上有什么我没看见的地方有问题吗?还是Word不支持上下文菜单上的多个项目?

office-js
1个回答
0
投票

我假设您尚未在清单文件的底部添加相关资源,因为在代码示例中没有看到这些资源。尝试更彻底地阅读文档的this部分,看看是否有帮助。

这里是我使用的示例清单,完成了我认为您要完成的任务:

<?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>18d46177-646b-4767-a5b8-efe907a59a95</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>Contoso</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="Patent Theory"/>
  <Description DefaultValue="A template to get started."/>
  <IconUrl DefaultValue="https://localhost:3000/assets/icon-32.png"/>
  <HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-80.png"/>
  <SupportUrl DefaultValue="https://www.contoso.com/help"/>
  <AppDomains>
    <AppDomain>contoso.com</AppDomain>
  </AppDomains>
  <Hosts>
    <Host Name="Document"/>
  </Hosts>
  <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="Document">
        <DesktopFormFactor>
          <GetStarted>
            <Title resid="GetStarted.Title"/>
            <Description resid="GetStarted.Description"/>
            <LearnMoreUrl resid="GetStarted.LearnMoreUrl"/>
          </GetStarted>
          <FunctionFile resid="Commands.Url"/>
          <ExtensionPoint xsi:type="PrimaryCommandSurface">
            <OfficeTab id="TabHome">
              <Group id="CommandsGroup">
                <Label resid="CommandsGroup.Label"/>
                <Icon>
                  <bt:Image size="16" resid="Icon.16x16"/>
                  <bt:Image size="32" resid="Icon.32x32"/>
                  <bt:Image size="80" resid="Icon.80x80"/>
                </Icon>
                <Control xsi:type="Button" id="TaskpaneButton">
                  <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="Taskpane.Url"/>
                  </Action>
                </Control>
              </Group>
            </OfficeTab>
          </ExtensionPoint>
          <!-- Datajoy New Extension Point -->
          <ExtensionPoint xsi:type="ContextMenu">
            <OfficeMenu id="ContextMenuText">
              <Control xsi:type="Menu" id="MarkAsProfanity.Menu">
                <Label resid="MarkAsProfanity.Label" />
                <Supertip>
                  <Title resid="MarkAsProfanity.Label" />
                  <Description resid="MarkAsProfanity.Description" />
                </Supertip>
                <Icon>
                  <bt:Image size="16" resid="Icon.16x16" />
                  <bt:Image size="32" resid="Icon.32x32" />
                  <bt:Image size="80" resid="Icon.80x80" />
                </Icon>
                <Items>
                  <Item id="IgnoreProfanity.Button">
                    <Label resid="IgnoreProfanity.Label"/>
                    <Supertip>
                      <Title resid="IgnoreProfanity.Label" />
                      <Description resid="IgnoreProfanity.Description" />
                    </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="ExecuteFunction">
                      <FunctionName>ignoreProfanity</FunctionName>
                    </Action>
                  </Item>
                  <Item id="ClaimsAndSpec.Button">
                    <Label resid="ClaimsAndSpec.Label"/>
                    <Supertip>
                      <Title resid="ClaimsAndSpec.Label" />
                      <Description resid="ClaimsAndSpec.Description" />
                    </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="ExecuteFunction">
                      <FunctionName>markAsClaimsAndSpecProfanity</FunctionName>
                    </Action>
                  </Item>
                  <Item id="Claims.Button">
                    <Label resid="Claims.Label"/>
                    <Supertip>
                      <Title resid="Claims.Label" />
                      <Description resid="Claims.Description" />
                    </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="ExecuteFunction">
                      <FunctionName>markAsClaimsProfanity</FunctionName>
                    </Action>
                  </Item>
                  <Item id="Spec.Button">
                    <Label resid="Spec.Label"/>
                    <Supertip>
                      <Title resid="Spec.Label" />
                      <Description resid="Spec.Description" />
                    </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="ExecuteFunction">
                      <FunctionName>markAsSpecProfanity</FunctionName>
                    </Action>
                  </Item>
                </Items>
              </Control>
            </OfficeMenu>
          </ExtensionPoint>
        </DesktopFormFactor>
      </Host>
    </Hosts>
    <Resources>
      <bt:Images>
        <bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/assets/icon-16.png"/>
        <bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/assets/icon-32.png"/>
        <bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.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="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="CommandsGroup.Label" DefaultValue="Commands Group"/>
        <bt:String id="TaskpaneButton.Label" DefaultValue="Show Taskpane"/>
        <bt:String id="MarkAsProfanity.Label" DefaultValue="Patent Theory"/>
        <bt:String id="ClaimsAndSpec.Label" DefaultValue="Mark in claims and spec"/>
        <bt:String id="Claims.Label" DefaultValue="Mark in claims"/>
        <bt:String id="Spec.Label" DefaultValue="Mark in spec"/>
        <bt:String id="IgnoreProfanity.Label" DefaultValue="Ignore profanity"/>
      </bt:ShortStrings>
      <bt:LongStrings>
        <bt:String id="GetStarted.Description" DefaultValue="Your sample add-in loaded succesfully. Go to the HOME tab and click the 'Show Taskpane' button to get started."/>
        <bt:String id="TaskpaneButton.Tooltip" DefaultValue="Click to Show a Taskpane"/>
        <bt:String id="MarkAsProfanity.Description" DefaultValue="Patent Theory"/>
        <bt:String id="ClaimsAndSpec.Description" DefaultValue="Mark in claims and spec"/>
        <bt:String id="Claims.Description" DefaultValue="Mark in claims"/>
        <bt:String id="Spec.Description" DefaultValue="Mark in spec"/>
        <bt:String id="IgnoreProfanity.Description" DefaultValue="Ignore profanity"/>
      </bt:LongStrings>
    </Resources>
  </VersionOverrides>
</OfficeApp>
© www.soinside.com 2019 - 2024. All rights reserved.