问题
Creating a manifest for a Word Add-in. I am trying to put TWO menu items on the ContextMenuText. I am following the guidance here: https://docs.microsoft.com/en-us/office/dev/add-ins/reference/manifest/control#menu-dropdown-button-controls. Here is where I get this understanding:
When used with a PrimaryCommandSurface or ContextMenu extension point, the menu control defines:
- A root-level menu item.
- A list of submenu items.
Everything I read says this is possible, and when I run NPM VALIDATE, it tells me that my manifest is valid. However, when I try to sideload with NPM START, the taskpane appears with the yellow warning that the manifest was not loaded. Also when I try to sideload in Word Online it tells me that my manifest is invalid.
If I define only a single top level CONTROL as a BUTTON it works fine. But I really need two items on the context menu.
Here is the relevant part of my manifest:
<!--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>
Is there something wrong with my manifest that I am just not seeing? Or does Word NOT support multiple items on the context menu?
回答1:
I assume you have not added the relevant resources at the bottom of the manifest file because I don't see them in your code sample. Try reading this part of the docs more thoroughly, and see if that helps.
Here is a sample manifest I used which accomplishes what I believe you are trying to accomplish:
<?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>
来源:https://stackoverflow.com/questions/61872534/contextmenu-in-word