需求:明细表字段所在单元格中录入一个值后将这个字段中所有的值按预设的规则进行替换。
方法:
- Imports SpreadsheetGear
- Imports C1.Silverlight
- Imports C1.Silverlight.C1MessageBoxButton
- Imports C1.Silverlight.C1MessageBoxIcon
- Imports Newtonsoft.Json
- Imports Newtonsoft.Json.Linq
- Imports System.Windows.forms
- Namespace ExcelViewVBDotnet
- Public Class StandardInterface
- '预留位置1
- '预留位置2
- Dim EV As SpreadsheetGear.Windows.Controls.WorkbookView,AW As SpreadsheetGear.IWorkbook,Range As SpreadsheetGear.IRange
- Dim ifLoop As Integer = 0
- Public Sub Workbook_Open(OldRoot As Object,NewRoot As Object,Excel As SpreadsheetGear.Windows.Controls.WorkbookView)
- EV = Excel
- Excel.GetLock()
- AW = Excel.ActiveWorkbook
- Range = AW.ActiveWorksheet.Range
- Excel.ReleaseLock()
- End Sub'打开时执行事件
- Public Sub RangeSelection(sender As Object,e As SpreadsheetGear.Windows.Controls.RangeSelectionChangedEventArgs)
- End Sub'单元格选择后执行的事件
- Public Sub RangeChanged(sender As Object,e As SpreadsheetGear.Windows.Controls.RangeChangedEventArgs)
- If e.Range.Intersect(Range("F_65443")) IsNot Nothing And ifLoop = 0 Then
- Dim Cell As IRange
- Dim ReplaceText As String
- For Each Cell In Range("F_65443")
- ReplaceText = Cell.Text
- ReplaceText = Replace(ReplaceText, "+", "+")
- ReplaceText = Replace(ReplaceText, "-", "-")
- ReplaceText = Replace(ReplaceText, "×", "*")
- ReplaceText = Replace(ReplaceText, "÷", "/")
- ReplaceText = Replace(ReplaceText, "(", "(")
- ReplaceText = Replace(ReplaceText, ")", ")")
- ReplaceText = Replace(ReplaceText, ".", ".")
- ifLoop = 1
- Cell.Value = ReplaceText
- ifLoop = 0
- Next
- End If
- End Sub'单元格编辑完成后执行事件
- Public Sub ButtunClick(sender As Object,e As SpreadsheetGear.Windows.Controls.ShapeActionEventArgs)
- End Sub'按钮/标签点击事件
- Public Sub FollowHyperlink(sender As Object)
- End Sub '暂不支持
- End Class
- ' 注:除事件字眼下可以自定义代码外的所有代码不允许改动,否则编译将有可能失败。
- End Namespace
复制代码
说明:Public Sub Workbook_Open前的声明Dim ifLoop As Integer = 0用于后续RangeChanged事件中进行判断,复制前改变ifLoop的值,这样当被循环触发时则条件不满足,从而避免被重复触发。赋值之后再改回来以便后续操作继续可以起作用。
|
hessen