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

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

⽤做excel插件开发,可能需要为excel添加⾃定义的⼯具栏。

这个也是⾮常的简单的。

以下是引⽤⽚段:
Public Class ConnectClass Connect
Implements Extensibility.IDTExtensibility2
Dim app As Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim addInInstance As Object
Dim pasteText As mandBarButton ‘定义⼀个⼯具栏按钮
Public Sub OnBeginShutdown()Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
End Sub
Public Sub OnAddInsUpdate()Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
End Sub
Public Sub OnStartupComplete()Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
End Sub
Public Sub OnDisconnection()Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnDisconnection
End Sub
Public Sub OnConnection()Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode,
ByVal addInInst As Object, ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnConnection
If TypeOf (application) Is Excel.Application Then app = CType(application, Excel.Application)
addInInstance = addInInst
wb = app.ActiveWorkbook
ws = CType(wb.ActiveSheet, Excel.Worksheet)
Dim toolbar As mandBar = Nothing
If Not app Is Nothing Then
toolbar = AddToolbar(app, "专⽤⼯具栏") ’添加⼯具栏
End If
’ 建⽴按钮添加⽂本
pasteText = MakeANewButton(toolbar, "Insert text",
1044, AddressOf pasteText_Click) ’添加⼯具栏按钮并帮定事件
End Sub
’添加⼯具栏
Private Function AddToolbar()Function AddToolbar(ByVal ex As Excel.Application, _
ByVal toolbarName As String) As mandBar
Dim toolBar As mandBar = Nothing
Try
’ 为add-in建⽴⼀个命令条
toolBar = CType(mandBars.Add(toolbarName,
Microsoft.Office.Core.MsoBarPosition.msoBarTop, , True),。

相关文档
最新文档