private void AddIn_Startup(object sender, System.EventArgs e) { Microsoft.Office.Core.CommandBar cmdBar = Application.CommandBars["cell"]; Microsoft.Office.Core.CommandBarControl comCtrl = cmdBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, Type.Missing, Type.Missing, Type.Missing, true); Microsoft.Office.Core.CommandBarButton comButton = comCtrl as Microsoft.Office.Core.CommandBarButton; comButton.Tag = "Validate"; comButton.Caption = "校验列"; comButton.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIcon; comButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnCalc_Click); }
private static bool IsInEditMode() { const int menuItemType = 1; const int newMenuId = 18; try { Microsoft.Office.Core.CommandBarControl newMenu = Globals.ThisAddIn.Application.CommandBars["Worksheet Menu Bar"].FindControl(menuItemType, newMenuId, Type.Missing, Type.Missing, true); return(newMenu != null && !newMenu.Enabled); } catch (Exception) { return(true); } }