分享
分享赚钱 收藏 举报 版权申诉 / 2

类型用VSTO给EXCEL添加右键菜单项.doc

  • 上传人:精品资料
  • 文档编号:8001303
  • 上传时间:2019-06-03
  • 格式:DOC
  • 页数:2
  • 大小:25KB
  • 配套讲稿:

    如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

    特殊限制:

    部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

    关 键  词:
    用VSTO给EXCEL添加右键菜单项.doc
    资源描述:

    1、如何用 VSTO 给 EXCEL 添加右键菜单项用 VSTO 操纵 EXCEL 使用 C#语言开发的 添加的右键菜单下面的确有“My Test”一项,但是点击却不能进入 OnCancelRelate_ClickEventHandler 函数 请问有谁知道为什么? 代码如下 / 删掉所有名为 DEL_SUB_ITEM_STR 的菜单项 Microsoft.Office.Core.CommandBar cellBar = Globals.ThisWorkbook.Application.CommandBars“cell“; Microsoft.Office.Core.CommandBarContr

    2、ols bars = cellBar.Controls; Microsoft.Office.Core.CommandBarControl newCtrl = bars.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, missing, missing, missing, true); /newCtrl.Caption = DEL_SUB_ITEM_STR; Microsoft.Office.Core.CommandBarButton newBtn = newCtrl as Microsoft.Office.Core.Comma

    3、ndBarButton; newBtn.Tag = “MyTest“; newBtn.Caption = “My Test“; newBtn.FaceId = 0163; newBtn.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonCaption; newBtn.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(OnCancelRelate_ClickEventHandler); =检查你添加的右键菜单项的类型=newBtn.St

    4、yle = Microsoft.Office.Core.MsoButtonStyle.msoButtonCaption; 这句不要估计就行了=以下是添加按钮,并且添加事件的实例,请 LZ 参考。 。 。 新建 excel-addin 程序。 1、添加引用 using Office = Microsoft.Office.Core;using System.Collections;2、声明对象 private Excel.Application AppExcel;private Office.CommandBarButton btnCalc;3、添加代码 /宿主启动时执行private void

    5、ThisAddIn_Startup(object sender, System.EventArgs e)AppExcel = Application;AddToolBar();4、以下是 AddToolBar()方法的实现 /添加工具栏private void AddToolBar()Office.CommandBars bars = AppExcel.CommandBars;if (bars = null)return;foreach (Office.CommandBar bar in bars)if (bar.Name.ToLower().Trim() = “mzbar“)bar.Dele

    6、te();Office.CommandBar mzBar = AppExcel.CommandBars.Add(“mzBar“, 1, null, null);if (mzBar != null)btnCalc = (Office.CommandBarButton)mzBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true);if (btnCalc != null)btnCalc.Caption = “计算(btnCalc.Style = Office.MsoButtonStyle.m

    7、soButtonIconAndCaption;btnCalc.TooltipText = “计算“;btnCalc.FaceId = 3277;btnCalc.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnCalc_Click);mzBar.Visible = true;4、以下是 btnCalc_Click 事件的实现 void btnCalc_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)/你要做的事情=Microsoft.Office.Core.CommandBarControl newCtrl 不要将 newctrl 定义成局部变量,要定义成全局变量

    展开阅读全文
    提示  道客多多所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
    关于本文
    本文标题:用VSTO给EXCEL添加右键菜单项.doc
    链接地址:https://www.docduoduo.com/p-8001303.html
    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    道客多多用户QQ群:832276834  微博官方号:道客多多官方   知乎号:道客多多

    Copyright© 2025 道客多多 docduoduo.com 网站版权所有世界地图

    经营许可证编号:粤ICP备2021046453号    营业执照商标

    1.png 2.png 3.png 4.png 5.png 6.png 7.png 8.png 9.png 10.png



    收起
    展开