Ms word Microsoft Word加载项-添加到上下文菜单
我已经为Word构建了一个外接程序,现在想添加一个选项,当用户突出显示一个Word并右键单击它时,可以从中调用函数。我找到了关于如何修改manifest.xml文件的文档,但它似乎没有显示如何添加到上下文菜单的完整示例,只显示了如何添加按钮和下拉菜单 文档还向我指出了一个页面显示示例,但同样缺少上下文菜单。它还指向视频,似乎显示了我在1:20左右想要什么,但也没有显示如何实现它 到目前为止,我有以下内容(添加在Ms word Microsoft Word加载项-添加到上下文菜单,ms-word,office-js,Ms Word,Office Js,我已经为Word构建了一个外接程序,现在想添加一个选项,当用户突出显示一个Word并右键单击它时,可以从中调用函数。我找到了关于如何修改manifest.xml文件的文档,但它似乎没有显示如何添加到上下文菜单的完整示例,只显示了如何添加按钮和下拉菜单 文档还向我指出了一个页面显示示例,但同样缺少上下文菜单。它还指向视频,似乎显示了我在1:20左右想要什么,但也没有显示如何实现它 到目前为止,我有以下内容(添加在下面): 当我添加此代码时(在默认的下),我的外接程序不再显示在“我的外接程序”菜单中
下面):
当我添加此代码时(在默认的
下),我的外接程序不再显示在“我的外接程序”菜单中。我下载了Microsoft的,它告诉我我的清单没有问题
我已将其缩小到导致问题的控件节点。如果我只添加:
<ExtensionPoint xsi:type="ContextMenu">
<OfficeMenu id="ContextMenuText">
</OfficeMenu>
</ExtensionPoint>
我的外接程序仍显示在菜单中。我还在
下的资源中添加了相关字符串:
<ExtensionPoint xsi:type="ContextMenu">
<OfficeMenu id="ContextMenuText">
<Control xsi:type="Menu" id="TestMenu">
<Label resid="ContextMenuLabel" />
<Supertip>
<Title resid="ContextualMenuTitle" />
<Description resid="ContextualMenuTitleDesc" />
</Supertip>
</Control>
</OfficeMenu>
</ExtensionPoint>
我的代码似乎与文档完全相同。我不确定从这里走到哪里。如果这改变了情况,我就在mac上。您尝试做的是可能的,而且您非常接近它:)
您已将ContextMenu控件选择为菜单
类型,而不是按钮
。这意味着您需要一些子菜单控件
从此处的文档:
每个组至少需要一个控件。控制元素可以是
按钮或菜单。使用“菜单”可指定以下项的下拉列表:
按钮控件。目前,仅支持按钮和菜单。看见
有关详细信息,请参见按钮控件和菜单控件部分
这意味着如果你想有嵌套菜单,你的清单是正确的,你只需要添加项目+图标到它。下面您可以看到打开任务窗格或执行函数的示例代码,具体取决于您单击的子菜单
<ExtensionPoint xsi:type="ContextMenu">
<OfficeMenu id="ContextMenuText">
<Control xsi:type="Menu" id="TestMenu">
<Label resid="ContextMenuLabel" />
<Supertip>
<Title resid="ContextualMenuTitle" />
<Description resid="ContextualMenuTitleDesc" />
</Supertip>
<Icon>
<bt:Image size="16" resid="your_icon_16"/>
<bt:Image size="32" resid="your_icon_32"/>
<bt:Image size="64" resid="your_icon_64"/>
<bt:Image size="80" resid="_icon_80"/>
</Icon>
<!-- Add your context sub-menu items -->
<Items>
<Item id="contextitem1">
<Label resid="somecontextlabel1"/>
<Supertip>
<Title resid="somecontexttitle1"/>
<Description resid="somedescription1"/>
</Supertip>
<Icon>
<bt:Image size="16" resid="someimage16"/>
<bt:Image size="32" resid="someimage32"/>
<bt:Image size="64" resid="someimage64"/>
<bt:Image size="80" resid="someimage80"/>
</Icon>
<Action xsi:type="ShowTaskpane">
<TaskpaneId>Mysupertaskpane1</TaskpaneId>
<SourceLocation resid="TaskPaneSourceLocation1"/>
</Action>
</Item>
<Item id="contextitem2">
<Label resid="somecontextlabel2"/>
<Supertip>
<Title resid="somecontexttitle2"/>
<Description resid="somedescription2"/>
</Supertip>
<Icon>
<bt:Image size="16" resid="someimage16"/>
<bt:Image size="32" resid="someimage32"/>
<bt:Image size="64" resid="someimage64"/>
<bt:Image size="80" resid="someimage80"/>
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>dosomejsmagic</FunctionName>
</Action>
</Item>
</Items>
</Control>
</OfficeMenu>
</ExtensionPoint>
我也有同样的问题。现在解决了。你的代码非常完美。只是需要在侧加载之前启动服务器。如果已使用office generator创建外接程序。然后
1.通过运行“npm start”启动外接程序
2.现在,在一个单独的终端中运行“npm run sideload”的sideload。
这解决了我的问题,希望也能解决你的问题。@淫秽-如果这解决了你的问题,我会很感激绿色勾号:)嘿@MaviDomates,谢谢你的回复,很抱歉回复太慢。你是对的,我并不是在试图做一个下拉列表。但是你确定我需要的是一个按钮吗?我仍然不明白为什么我需要你发布的代码中的部分。我正在尝试向右键单击菜单添加一个部分,这样当用户突出显示文档中的某个单词时,他们可以右键单击该单词并执行一个函数。右键单击菜单中没有图像?我尝试了你发布的代码,但没有成功。文本左侧的右键单击菜单中有图像。谢谢你的帮助。我仍然有一些问题,并对我原来的帖子进行了编辑。你有时间看一下吗?
<bt:String id="openSearchButtonLabel" DefaultValue="Check it out!" />
<bt:String id="openSearchButtonTitle" DefaultValue="Hover over me" />
<bt:String id="openSearchButtonDescription" DefaultValue="For more info go here" />
<ExtensionPoint xsi:type="ContextMenu">
<OfficeMenu id="ContextMenuText">
<Control xsi:type="Menu" id="TestMenu">
<Label resid="ContextMenuLabel" />
<Supertip>
<Title resid="ContextualMenuTitle" />
<Description resid="ContextualMenuTitleDesc" />
</Supertip>
<Icon>
<bt:Image size="16" resid="your_icon_16"/>
<bt:Image size="32" resid="your_icon_32"/>
<bt:Image size="64" resid="your_icon_64"/>
<bt:Image size="80" resid="_icon_80"/>
</Icon>
<!-- Add your context sub-menu items -->
<Items>
<Item id="contextitem1">
<Label resid="somecontextlabel1"/>
<Supertip>
<Title resid="somecontexttitle1"/>
<Description resid="somedescription1"/>
</Supertip>
<Icon>
<bt:Image size="16" resid="someimage16"/>
<bt:Image size="32" resid="someimage32"/>
<bt:Image size="64" resid="someimage64"/>
<bt:Image size="80" resid="someimage80"/>
</Icon>
<Action xsi:type="ShowTaskpane">
<TaskpaneId>Mysupertaskpane1</TaskpaneId>
<SourceLocation resid="TaskPaneSourceLocation1"/>
</Action>
</Item>
<Item id="contextitem2">
<Label resid="somecontextlabel2"/>
<Supertip>
<Title resid="somecontexttitle2"/>
<Description resid="somedescription2"/>
</Supertip>
<Icon>
<bt:Image size="16" resid="someimage16"/>
<bt:Image size="32" resid="someimage32"/>
<bt:Image size="64" resid="someimage64"/>
<bt:Image size="80" resid="someimage80"/>
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>dosomejsmagic</FunctionName>
</Action>
</Item>
</Items>
</Control>
</OfficeMenu>
</ExtensionPoint>
<ExtensionPoint xsi:type="ContextMenu">
<OfficeMenu id="ContextMenuText">
<Control xsi:type="Button" id="Button1Id1">
<Label resid="residLabel" />
<Tooltip resid="residToolTip" />
<Supertip>
<Title resid="residLabel" />
<Description resid="residToolTip" />
</Supertip>
<Icon>
<bt:Image size="16" resid="icon1_32x32" />
<bt:Image size="32" resid="icon1_32x32" />
<bt:Image size="80" resid="icon1_32x32" />
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>getData</FunctionName>
</Action>
</Control>
</OfficeMenu>
</ExtensionPoint>