校验身份证位数的VBA
如果身份证位数不是18,则字段区域变红。
在身份证字段的右侧添加一个判断字段,判断字段添加函数来判断身份证字段的值是否正确
VBA使用方法:直接复制下面的内容,把T_255替换成自己的表名,把F_51655替换成需要判断的字段别名
- 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
-
- 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)
- ActiveWorkbook.WorkbookSet.GetLock()
- '定义一个明细表的范围:T_155
- Dim Rng As IRange = e.RangeSelection.Intersect(Range("T_255"))
- Dim MyRange As IRange
- '如果选择区域不在设定的范围内,不执行下面的代码
- If Rng IsNot Nothing Then
-
- ' ActiveWorkbook.ActiveWorksheet.ProtectContents = False
- ' C1MessageBox.Show("你好!", "提示", OK, Information)
- '循环判断F_51527_,F_51533_,F_51534_三块区域
- For Each MyRange In Range("F_51655")
- '判断区域的值是否等于"TRUE"
- If MyRange.value = "1" Then
- '满足条件的单元格的值左侧一格单元格锁定
- ' MyRange.Cells(0,-9).Locked = True
- MyRange.Cells(0,-9).Interior.Color = Color.FromArgb(255,0,0)
- Else
- '不满足条件的单元格的值左侧一格单元格解锁
- ' MyRange.Cells(0,-9).Locked = False
- MyRange.Cells(0,-9).Interior.Color = Color.FromArgb(255,255,255)
- End If
- Next
- End If
- ActiveWorkbook.WorkbookSet.ReleaseLock()
-
- End Sub'单元格选择后执行的事件
- Public Sub RangeChanged(sender As Object,e As SpreadsheetGear.Windows.Controls.RangeChangedEventArgs)
- 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
复制代码
|
|
kuaibiao_