加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

vb.net开发中使用excel插件代码

发布时间:2020-12-16 23:13:47 所属栏目:大数据 来源:网络整理
导读:PublicClassConnectClassConnect ImplementsExtensibility.IDTExtensibility2 DimappAsExcel.Application DimwbAsExcel.Workbook DimwsAsExcel.Worksheet DimaddInInstanceAsObject DimpasteTextAsMicrosoft.Office.Core.CommandBarButton‘定义一个工具栏按

 PublicClassConnectClassConnect   ImplementsExtensibility.IDTExtensibility2   DimappAsExcel.Application   DimwbAsExcel.Workbook   DimwsAsExcel.Worksheet   DimaddInInstanceAsObject   DimpasteTextAsMicrosoft.Office.Core.CommandBarButton‘定义一个工具栏按钮   PublicSubOnBeginShutdown()SubOnBeginShutdown(ByRefcustomAsSystem.Array)ImplementsExtensibility.IDTExtensibility2.OnBeginShutdown   EndSub   PublicSubOnAddInsUpdate()SubOnAddInsUpdate(ByRefcustomAsSystem.Array)ImplementsExtensibility.IDTExtensibility2.OnAddInsUpdate   EndSub   PublicSubOnStartupComplete()SubOnStartupComplete(ByRefcustomAsSystem.Array)ImplementsExtensibility.IDTExtensibility2.OnStartupComplete   EndSub   PublicSubOnDisconnection()SubOnDisconnection(ByValRemoveModeAsExtensibility.ext_DisconnectMode,ByRefcustomAsSystem.Array)   ImplementsExtensibility.IDTExtensibility2.OnDisconnection   EndSub   PublicSubOnConnection()SubOnConnection(ByValapplicationAsObject,ByValconnectModeAsExtensibility.ext_ConnectMode,  ByValaddInInstAsObject,ByRefcustomAsSystem.Array)   ImplementsExtensibility.IDTExtensibility2.OnConnection   IfTypeOf(application)IsExcel.ApplicationThenapp=CType(application,Excel.Application)   addInInstance=addInInst   wb=app.ActiveWorkbook   ws=CType(wb.ActiveSheet,Excel.Worksheet)   DimtoolbarAsMicrosoft.Office.Core.CommandBar=Nothing   IfNotappIsNothingThen   toolbar=AddToolbar(app,"专用工具栏")’添加工具栏   EndIf   ’建立按钮添加文本   pasteText=MakeANewButton(toolbar,"Inserttext",  1044,AddressOfpasteText_Click)’添加工具栏按钮并帮定事件   EndSub   ’添加工具栏   PrivateFunctionAddToolbar()FunctionAddToolbar(ByValexAsExcel.Application,_   ByValtoolbarNameAsString)AsMicrosoft.Office.Core.CommandBar   DimtoolBarAsMicrosoft.Office.Core.CommandBar=Nothing   Try   ’为add-in建立一个命令条   toolBar=CType(ex.CommandBars.Add(toolbarName,  Microsoft.Office.Core.MsoBarPosition.msoBarTop,True),  Microsoft.Office.Core.CommandBar)   toolBar.Visible=True   ReturntoolBar   Catch   ReturnNothing   EndTry   EndFunction   ’在工具栏上添加一个按钮   PrivateFunctionMakeANewButton()FunctionMakeANewButton(ByValcommandBarAsMicrosoft.Office.Core.CommandBar,ByValcaption   AsString,ByValfaceIDAsInteger,ByValclickHandlerAsMicrosoft.Office.   Core._CommandBarButtonEvents_ClickEventHandler)AsMicrosoft.Office.Core.CommandBarButton   Try   DimnewButtonAsMicrosoft.Office.Core.CommandBarButton   newButton=CType(commandBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton),Microsoft.Office.Core.CommandBarButton)   newButton.Caption=caption   newButton.FaceId=faceID   AddHandlernewButton.Click,clickHandler   ReturnnewButton   CatchexAsSystem.Exception   ReturnNothing   EndTry   EndFunction   ’点击工具条按钮时应该执行的程序   PublicSubpasteText_Click()SubpasteText_Click(ByValbarButtonAsMicrosoft.Office.Core.CommandBarButton,ByRefsomeBoolAsBoolean)   DimtextAsString=""   DimdataAsSystem.Windows.Forms.IDataObject=System.Windows.Forms.Clipboard.GetDataObject()   Ifdata.GetDataPresent(System.Windows.Forms.DataFormats.Text)Then   text=data.GetData(System.Windows.Forms.DataFormats.Text).ToString()   If(NotappIsNothing)Then   Me.app.ActiveCell.Value=text   EndIf   EndIf   EndSub   EndClass

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读