1

I am trying to build a Webaddin for Excel using OfficeJS.

I couldn't find anything mentioned in the OfficeJS docs for my requirement.

My requirement is to group or distinguish between multiple Sub-Menu Items.

Something like in the image below

1st Image

Group Sub-Menus

or

2nd Image

Seperator

This is how my right-click contextual Menu looks like with multiple Sub-Menu Items

3rd Image

My submenu

I want to add a few more sub-menus and group Sub-Menu-1 and Sub-Menu-2 as Group 1 and Sub-Menu-3 and Sub-Menu-4 as Group 2.

I want to show the Group 1 and Group 2 as headings just like the 'Paste Options:' in the 1st image or show a a line seperating the 2 groups like in the 2nd image.

This is the code in my manifest file for right click contextual menu

<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>
                                                <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>
                            
                                            </Items>
                                        </Control>
                      </OfficeMenu>
                  </ExtensionPoint>
WorksOnMyLocal
  • 1,617
  • 3
  • 23
  • 44

1 Answers1

0

The OfficeMenu defines a collection of controls to be added to the Office context menu. Sounds like you need to define several context menus with your items:

<OfficeMenu id="ContextMenuCell">
   <Control xsi:type="Menu" id="FirstMenu">
      <Items>
       ...
      </Items>
   </Control>

   <Control xsi:type="Menu" id="SecondMenu">
       <Items>
        ...
       </Items>
   </Control>
</OfficeMenu>
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • 1
    though the OfficeJS documentation gives an example to add multiple controls inside the OfficeMenu , the reality is that adding multiple controls to OfficeMenu is not supported by OfficeJS as of June 2023. I have already raised a new ticket(https://github.com/OfficeDev/office-js/issues/3422) for the same issue with the microsoft, and is yet to be triaged. – WorksOnMyLocal Jun 20 '23 at 12:27
  • 1
    Interesting. Thanks for sharing the link for other SO readers. – Eugene Astafiev Jun 20 '23 at 12:43