Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自定义上下文菜单在Excel中不可见(VSTO C#)_C#_Excel_Vsto_Contextmenu_Ribbon - Fatal编程技术网

自定义上下文菜单在Excel中不可见(VSTO C#)

自定义上下文菜单在Excel中不可见(VSTO C#),c#,excel,vsto,contextmenu,ribbon,C#,Excel,Vsto,Contextmenu,Ribbon,正在尝试使用自定义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> <

正在尝试使用自定义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>

这是Addin.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
    }
}
namespace DemoAddin
{
公共部分类ThisAddIn
{
公共字符串GetSynchronizationLabel(Office.IRibbonControl控件)
{
返回“同步”;
}
public void ShowMessageClick(Office.IRibbonControl控件)
{
Show(“您已经单击了同步上下文菜单项”、“信息”,MessageBoxButtons.OK,MessageBoxIcon.Information);
}
受保护的覆盖Microsoft.Office.Core.IribboneExtensibility CreateRibboneExtensibilityObject()
{
返回新的Ribbon2();
}
私有void ThisAddIn_启动(对象发送方,System.EventArgs e)
{
}
私有void ThisAddIn_关闭(对象发送方,System.EventArgs e)
{
}
#区域VSTO生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InternalStartup()
{
this.Startup+=new System.EventHandler(ThisAddIn\u启动);
this.Shutdown+=new System.EventHandler(ThisAddIn\u Shutdown);
}
#端区
}
}

我使用此代码添加的选项在上下文菜单中不可见

只需将上下文菜单的idMso从ContextMenuText更改为“ContextMenuCell”即可解决此问题

<contextMenus>
    <contextMenu idMso="ContextMenuCell">
      <button id="mybutton" onAction="ShowMessageClick" getLabel="GetSynchronisationLabel"/>

    </contextMenu>
  </contextMenus>

只需将上下文菜单的idMso从ContextMenuText更改为“ContextMenuCell”即可解决此问题

<contextMenus>
    <contextMenu idMso="ContextMenuCell">
      <button id="mybutton" onAction="ShowMessageClick" getLabel="GetSynchronisationLabel"/>

    </contextMenu>
  </contextMenus>