复制下面的代码到快表VBA编辑器中,生成DLL后应用于系统。不支持3.9.0以下版本,使用前请将快表升级至3.9.0版本以上。
- Imports SpreadsheetGear
- Imports System.Windows.forms
- Namespace ExcelViewVBDotnet
- Public Class StandardInterface '自定义名称
- '预留位置1
- '预留位置2
- Dim AW As SpreadsheetGear.IWorkbook,Range As SpreadsheetGear.IRange
- Dim CF,TS,VW As Object
- Public Sub Workbook_Open(OldRoot As Object,NewRoot As Object,Excel As SpreadsheetGear.Windows.Forms.WorkbookView)
- Excel.GetLock()
- AW = Excel.ActiveWorkbook
- Range = AW.ActiveWorksheet.Range
- Excel.ReleaseLock()
-
- CF = OldRoot.Children(1) '绑定工具条触发,不能测试运行
- TS = OldRoot.Children(5) '绑定工具条区域,不能测试运行
- '工具条添加第一个按钮
- Dim BT1 As New Button
- BT1.Name = "BT_AN1" '按钮名,不能与其他按钮名称重复,下同。
- BT1.Content = "第一个按钮" '按钮显示的名称,自定义写入欲显示的名称。下同
- BT1.Margin= New Thickness(0, 2, 0, 2)
- BT1.Padding= New Thickness(13, 3, 13, 3)
- BT1.Style = Application.Current.Resources("ButtonStyle3")
- BT1.Foreground = Application.Current.Resources("Foreground1")
- TS.Children.Insert(16, BT1) '插入按钮的位置,多个按钮时顺序往下排
-
- '位置:2保存3新增4提交5退回6打印7预览8导出9捕获10上传图片11上传附件12插入行13插多行14删除行15查找16最后
-
- '工具条添加第二个按钮
- Dim BT2 As New Button
- BT2.Name = "BT_AN2"
- BT2.Content = "第二个按钮"
- BT2.Margin= New Thickness(0, 2, 0, 2)
- BT2.Padding= New Thickness(13, 3, 13, 3)
- BT2.Style = Application.Current.Resources("ButtonStyle3")
- BT2.Foreground = Application.Current.Resources("Foreground1")
- TS.Children.Insert(17, BT2)
-
-
-
- '工具条添加第三个按钮,点击按钮时执行提取公式
- Dim BT3 As New Button
- BT3.Name = "BT_TQ"
- BT3.Content = "执行提取公式"
- BT3.Margin= New Thickness(0, 2, 0, 2)
- BT3.Padding= New Thickness(13, 3, 13, 3)
- BT3.Style = Application.Current.Resources("ButtonStyle3")
- BT3.Foreground = Application.Current.Resources("Foreground1")
- AddHandler BT3.Click, Sub()
- CF.Tag="1,缴费查询" '公式类型:1为提取,2为传递。逗号后加执行的公式名称,与表间公式中的显示的名称一致
- CF.Text="#执行公式" '执行提取公式写入"#执行公式",执行SQL语句写入"#执行SQL"
- End Sub
- TS.Children.Insert(18, BT3)
- '工具条添加第四个按钮,点击按钮时执行SQL语句
- Dim BT4 As New Button
- BT4.Name = "BT_SQL"
- BT4.Content = "执行SQL语句"
- BT4.Margin= New Thickness(0, 2, 0, 2)
- BT4.Padding= New Thickness(13, 3, 13, 3)
- BT4.Style = Application.Current.Resources("ButtonStyle3")
- BT4.Foreground = Application.Current.Resources("Foreground1")
- AddHandler BT4.Click, Sub()
- CF.Tag="Delete From T_33 Where F_117 = '张建斌'|删除完毕!" '执行的SQL语句,语句后竖线分隔符及后面显示的文字为在语句执行完成后弹出提示内容。
- CF.Text="#执行SQL"
- End Sub
- TS.Children.Insert(19, BT4)
-
- '工具条添加第五个按钮,点击按钮时执行公式或SQL时加入IF判断示例
- Dim BT5 As New Button
- BT5.Name = "BT_SQL2"
- BT5.Content = "有条件执行语句"
- BT5.Margin= New Thickness(0, 2, 0, 2)
- BT5.Padding= New Thickness(13, 3, 13, 3)
- BT5.Style = Application.Current.Resources("ButtonStyle3")
- BT5.Foreground = Application.Current.Resources("Foreground1")
- AddHandler BT5.Click, Sub()
- AW.WorkbookSet.GetLock()
- IF Range("E2").Value <> "2015" Then '执行公式或语句时,可以自由写入相关代码,这里以IF作示例。
- Messagebox.show("对不起!当前年份不允许删除,请更改年份后执行!")
- Else
- CF.Tag="Delete From T_33 Where F_117 = '张建斌'|删除完毕!"
- CF.Text="#执行SQL"
- End if
- AW.WorkbookSet.ReleaseLock()
- End Sub
- TS.Children.Insert(20, BT5)
-
- '工具条添加第六个按钮,点击按钮时执行提取公式
- Dim BT6 As New Button
- BT6.Name = "BT_TQ2"
- BT6.Content = "传递填报收款凭证"
- BT6.Margin= New Thickness(0, 2, 0, 2)
- BT6.Padding= New Thickness(13, 3, 13, 3)
- BT6.Style = Application.Current.Resources("ButtonStyle3")
- BT6.Foreground = Application.Current.Resources("Foreground1")
- AddHandler BT6.Click, Sub()
- CF.Tag="2,传递填报收款凭证" '公式类型:1为提取,2为传递。逗号后加执行的公式名称,与表间公式中的显示的名称一致
- CF.Text="#执行公式" '执行提取公式写入"#执行公式",执行SQL语句写入"#执行SQL"
- End Sub
- TS.Children.Insert(21, BT6)
-
- '位置:2保存3新增4提交5退回6打印7预览8导出9捕获10上传图片11上传附件12插入行13插多行14删除行15查找16最后
- End Sub'打开时执行事件
- Public Sub RangeSelection(sender As Object,e As SpreadsheetGear.Windows.Forms.RangeSelectionChangedEventArgs)
- End Sub'单元格选择后执行的事件
- Public Sub RangeChanged(sender As Object,e As SpreadsheetGear.Windows.Forms.RangeChangedEventArgs)
-
- End Sub'单元格编辑完成后执行事件
- Public Sub ButtunClick(sender As Object,e As SpreadsheetGear.Windows.Forms.ShapeActionEventArgs)
- End Sub'按钮/标签点击事件
- Public Sub FollowHyperlink(sender As Object)
-
- End Sub '暂不支持
- End Class
- '注:除事件字眼下可以自定义代码外的所有代码不允许改动,否则编译将有可能失败。
- End Namespace
复制代码
|
admin