尝试使用自定义UI在Excel单元格右键菜单中创建一些选项。 这是XML
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<ribbon>
</ribbon>
<contextMenus>
<contextMenu idMso="ContextMenuText">
<button id="mybutton" onAction="ShowMessageClick" getLabel="GetSynchronisationLabel"/>
</contextMenu>
</contextMenus>
</customUI>
这是ThisAddin.cs
namespace DemoAddin
{
public partial class ThisAddIn
{
public string GetSynchronisationLabel(Office.IRibbonControl control)
{
return "Synchronize";
}
public void ShowMessageClick(Office.IRibbonControl control)
{
MessageBox.Show("You've clicked the synchronize context menu item", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new Ribbon2();
}
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
我使用此代码添加的选项在上下文菜单中不可见。
答案 0 :(得分:0)
只需将上下文菜单的idMso从 ContextMenuText 更改为“ ContextMenuCell ”即可解决问题。
<contextMenus>
<contextMenu idMso="ContextMenuCell">
<button id="mybutton" onAction="ShowMessageClick" getLabel="GetSynchronisationLabel"/>
</contextMenu>
</contextMenus>