如何在Excel Web加载项右键上下文菜单中分组子菜单项?
OfficeJS Excel Web加载项:右键上下文菜单分组实现方案
针对右键上下文菜单的分组需求,以下是两种符合要求的实现方案,直接修改Manifest.xml即可完成:
方案一:用分隔线区分菜单组
在两组菜单项之间插入<Separator>控件,就能添加默认的分隔线,清晰划分不同组。
修改后的Manifest代码示例:
<ExtensionPoint xsi:type="ContextMenu"> <OfficeMenu id="ContextMenuCell"> <Control xsi:type="Menu" id="Menu"> <Label resid="Dropdown.Label" /> <Supertip> <Title resid="Dropdown.Label" /> <Description resid="Dropdown.Tooltip" /> </Supertip> <Items> <!-- Group 1 --> <Item id="Menu.Item1"> <Label resid="Item1.Label"/> <Supertip> <Title resid="Item1.Label" /> <Description resid="Item1.Tooltip" /> </Supertip> <Action xsi:type="ExecuteFunction"> <FunctionName>signOff</FunctionName> </Action> <Enabled>false</Enabled> </Item> <Item id="Menu.Item2"> <Label resid="Item2.Label"/> <Supertip> <Title resid="Item2.Label" /> <Description resid="Item2.Tooltip" /> </Supertip> <Action xsi:type="ExecuteFunction"> <FunctionName>signOff2</FunctionName> </Action> </Item> <!-- 分隔线 --> <Separator id="Menu.Separator1"/> <!-- Group 2 --> <Item id="Menu.Item3"> <Label resid="Item3.Label"/> <Supertip> <Title resid="Item3.Label" /> <Description resid="Item3.Tooltip" /> </Supertip> <Action xsi:type="ExecuteFunction"> <FunctionName>function3</FunctionName> </Action> </Item> <Item id="Menu.Item4"> <Label resid="Item4.Label"/> <Supertip> <Title resid="Item4.Label" /> <Description resid="Item4.Tooltip" /> </Supertip> <Action xsi:type="ExecuteFunction"> <FunctionName>function4</FunctionName> </Action> </Item> </Items> </Control> </OfficeMenu> </ExtensionPoint>
方案二:添加分组标题(类似"Paste Options:"样式)
使用<Control xsi:type="Label">控件作为分组标题,需要在资源文件中定义标题文本的resid。
步骤1:修改Manifest.xml添加分组标题控件
<ExtensionPoint xsi:type="ContextMenu"> <OfficeMenu id="ContextMenuCell"> <Control xsi:type="Menu" id="Menu"> <Label resid="Dropdown.Label" /> <Supertip> <Title resid="Dropdown.Label" /> <Description resid="Dropdown.Tooltip" /> </Supertip> <Items> <!-- Group 1 标题 --> <Control xsi:type="Label" id="Menu.Group1Label"> <Label resid="Group1.Label"/> </Control> <!-- Group 1 菜单项 --> <Item id="Menu.Item1"> <Label resid="Item1.Label"/> <Supertip> <Title resid="Item1.Label" /> <Description resid="Item1.Tooltip" /> </Supertip> <Action xsi:type="ExecuteFunction"> <FunctionName>signOff</FunctionName> </Action> <Enabled>false</Enabled> </Item> <Item id="Menu.Item2"> <Label resid="Item2.Label"/> <Supertip> <Title resid="Item2.Label" /> <Description resid="Item2.Tooltip" /> </Supertip> <Action xsi:type="ExecuteFunction"> <FunctionName>signOff2</FunctionName> </Action> </Item> <!-- 分隔线(可选,增强区分度) --> <Separator id="Menu.Separator1"/> <!-- Group 2 标题 --> <Control xsi:type="Label" id="Menu.Group2Label"> <Label resid="Group2.Label"/> </Control> <!-- Group 2 菜单项 --> <Item id="Menu.Item3"> <Label resid="Item3.Label"/> <Supertip> <Title resid="Item3.Label" /> <Description resid="Item3.Tooltip" /> </Supertip> <Action xsi:type="ExecuteFunction"> <FunctionName>function3</FunctionName> </Action> </Item> <Item id="Menu.Item4"> <Label resid="Item4.Label"/> <Supertip> <Title resid="Item4.Label" /> <Description resid="Item4.Tooltip" /> </Supertip> <Action xsi:type="ExecuteFunction"> <FunctionName>function4</FunctionName> </Action> </Item> </Items> </Control> </OfficeMenu> </ExtensionPoint>
步骤2:在资源文件中添加分组标题文本
打开resources.resx(或对应语言的资源文件),添加以下内容:
<data name="Group1.Label" xml:space="preserve"> <value>Group 1</value> </data> <data name="Group2.Label" xml:space="preserve"> <value>Group 2</value> </data>
注意:分组标题控件仅支持在Office 365最新版本中显示,需确保加载项目标环境满足版本要求。
内容的提问来源于stack exchange,提问作者WorksOnMyLocal
相关产品推荐
相关产品推荐

