我正在按照此示例为VSTO创建一个excel加载项的自定义右键单击自定义菜单,并在特定条件下显示它(右键单击Excel命名表的范围内).
当我在命名表格范围外单击鼠标右键时,我从示例中修改的代码版本就像一个魅力:

但是当您在命名表范围内右键单击时,它不会显示:

我想它与快速分析功能有关,干扰了我的自定义上下文菜单覆盖.这是我在ThisAddin.cs中使用的代码:
void Application_SheetBeforeRightClick(object worksheet, Excel.Range range, ref bool cancel)
{
GetCellContextMenu().Reset(); // reset the cell context menu back to the default
// If the selected range belongs within a named excel table we display the refresh menu item at the right click context menu.
if (true) //range.IntersectsWithAnyExcelTable()) <-- this code works fine but I commented it out for the purpose of showing the problem (in this case the custom popup meny should appear ALWAYS):
{ …Run Code Online (Sandbox Code Playgroud)