Visual Studio中ExcelWorkBook项目创建加载项菜单

 1   public partial class Sheet1
 2     {
 3         private void Sheet1_Startup(object sender, System.EventArgs e)
 4         {
 5             //#region VSTO generated code
 6 
 7             //this.Application = (Excel.Application)Microsoft.Office.Tools.Excel.ExcelLocale1033Proxy.Wrap(typeof(Excel.Application), this.Application);
 8 
 9             //#endregion
10             this.AddMenu();
11      
12             
13         }
14 
15         private void Sheet1_Shutdown(object sender, System.EventArgs e)
16         {
17 
18         }
19 
20         #region VSTO 设计器生成的代码
21 
22         /// <summary>
23         /// 设计器支持所需的方法 - 不要
24         /// 使用代码编辑器修改此方法的内容。
25         /// </summary>
26         private void InternalStartup()
27         {
28             this.Startup += new System.EventHandler(Sheet1_Startup);
29             this.Shutdown += new System.EventHandler(Sheet1_Shutdown);
30         }
31 
32         #endregion
33 
34         private void AddMenu()
35         {
36             //获取Outlook的MenuBar 
37             Office.CommandBar bar = this.Application.CommandBars.ActiveMenuBar;
38             //创建顶级菜单 
39             Office.CommandBarControl menuTop = bar.Controls.Add(Office.MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, bar.Controls.Count, true);
40             menuTop.Caption = "我的菜单";
41 
42             Office.CommandBarPopup commandBarPopupTmp = menuTop.Control as Office.CommandBarPopup;
43 
44             Office.CommandBarControl menuGroup = null;
45             Office.CommandBarControl menuCreateMail = null;
46 
47             if (commandBarPopupTmp.Controls.Count == 0)
48             {
49                 menuGroup = commandBarPopupTmp.Controls.Add(Office.MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing,System.Type.Missing, true);
50             }
51             else
52             {
53                 menuGroup = commandBarPopupTmp.Controls.Add(Office.MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, commandBarPopupTmp.Controls.Count, true);
54             }
55 
56             menuCreateMail = commandBarPopupTmp.Controls.Add(Office.MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, 1, true);
57 
58             menuGroup.Caption = "菜单组";
59 
60             menuCreateMail.Caption = "保存焊接记录";
61 
62             Office.CommandBarButton buttonMenu = menuCreateMail as Office.CommandBarButton;
63             buttonMenu.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(buttonMenu_Click);
64           
65         }
66 
67 
68         void buttonMenu_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
69         {
70             MessageBox.Show("222");
71         }
72     }

 

转载于:https://www.cnblogs.com/iamwxy/archive/2013/01/16/2862538.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值