c# – Quick Analysis右键单击上下文菜单会被Quick Analysis默认
发布时间:2020-12-16 02:00:59 所属栏目:百科 来源:网络整理
导读:我正在关注 this example为使用VSTO的excel加载项创建自定义右键单击自定义菜单,并在特定条件下显示它(右键单击Excel命名表的范围内). 当我在命名表范围外右键单击时,我从示例中修改的代码版本就像一个魅力: 但是当您在命名表范围内右键单击时,它不会显示:
我正在关注
this example为使用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): { const OfficeCore.MsoControlType menuItem = OfficeCore.MsoControlType.msoControlButton; var refreshMenuItem = (OfficeCore.CommandBarButton)GetCellContextMenu().Controls.Add(menuItem,missing,1,true);// where missing = global::System.Type.Missing; refreshMenuItem.Style = OfficeCore.MsoButtonStyle.msoButtonCaption; refreshMenuItem.Caption = "Refresh My Data"; refreshMenuItem.Click -= RefreshMenuItemClick; refreshMenuItem.Click += RefreshMenuItemClick; } } 并且不要忘记在加载项启动时订阅事件: Application.SheetBeforeRightClick += Application_SheetBeforeRightClick; 我怎么能: >尽管进行了快速分析,但仍显示我的自定义菜单. 解决方法
Excel对表使用单独的右键单击菜单.
我只会说VBA,所以你必须翻译… 右键单击“普通”单元格时,将使用CommandBars(“单元格”)菜单. 在表中右键单击时,将使用CommandBars(“列表范围弹出”)菜单. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |