Jer*_*son 6 c# excel vsto contextmenu
我尝试了3种不同的代码示例,但都失败了.
这是来自MSFT员工的代码(如何在范围上显示上下文菜单),其他两个样本具有完全相同的代码:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
CommandBar cellbar = this.Application.CommandBars["Cell"];
CommandBarButton button = (CommandBarButton) cellbar.FindControl(MsoControlType.msoControlButton, 0, "MYRIGHTCLICKMENU", Missing.Value, Missing.Value);
if (button == null)
{
// add the button
button = (CommandBarButton) cellbar.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, cellbar.Controls.Count, true);
button.Caption = "Refresh";
button.BeginGroup = true;
button.Tag = "MYRIGHTCLICKMENU";
button.Click += new _CommandBarButtonEvents_ClickEventHandler(MyButton_Click);
}
}
private void MyButton_Click(CommandBarButton cmdBarbutton, ref bool cancel)
{
System.Windows.Forms.MessageBox.Show("MyButton was Clicked", "MyCOMAddin");
}
Run Code Online (Sandbox Code Playgroud)
当我右键单击一个单元格时,我希望看到一个名为Refresh的菜单项.然而,运行上面的代码(在Excel 2010中)没有"刷新"菜单项.
非常感谢我可能缺少的任何提示,或者这个功能是否从2007年改为2010年?
检查这种类型的代码是否存在(在您自己的外接程序或您公司使用的任何其他外接程序中),以及是否将其注释掉或将其移至外接程序的 _Shutdown 事件。
//reset commandbars
Application.CommandBars["Cell"].Reset();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5059 次 |
| 最近记录: |