【问题标题】:Custom context menu not visible in Excel (VSTO C#)自定义上下文菜单在 Excel (VSTO C#) 中不可见
【发布时间】:2016-12-25 21:16:02
【问题描述】:

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

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

【问题讨论】:

    标签: c# excel vsto contextmenu ribbon


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多