VBA使用EXCEL读取身份证阅读器获得证件信息
时间:2021.02.10 创作:欧阳史 本代码实现了在EXCEL中调用精伦身份证阅读器控件(可在网上百度精伦二次开发包,里面有)读取身份证信息,可根据实际情况修改相关代码,源文件可在EXCELhome网站搜索下载。
Private Declare Function InitComm Lib \"Sdtapi.dll\" (ByVal iPort As Integer) As Integer Private
Declare
Function
CloseComm
Lib
\"Sdtapi.dll\" () As Integer Private
Declare
Function
Authenticate
Lib
\"Sdtapi.dll\" () As Integer Private
Declare
Function
ReadBaseInfos
Lib
\"Sdtapi.dll\" (ByVal iname As String, ByVal isex As String, ByVal folk As String, ByVal birthday As String, ByVal code As String, ByVal addr As String, ByVal agency As String, ByVal startdate As String, ByVal enddate As String) As Integer Sub 启动_Click()
'On Error Resume Next
欧阳史创编 2021..02.10
欧阳史创编 2021..02.10
Dim n, ret, nLen
Dim iname As String * 31 Dim isex As String * 3 Dim folk As String * 10 Dim code As String * 19 Dim addr As String * 71 Dim birthday As String * 9 Dim startdate As String * 9 Dim enddate As String * 9 Dim agency As String * 31 Dim Msg As String * 300 Dim Msg1 As String * 256 Dim IINSNDN As String * Dim SAMID As String * 36 Dim LenT As Integer ret = InitComm(\"1001\") If Err Then Err.Clear
MsgBox \"端口错误\提示\" Exit Sub End If
ret = Authenticate()
欧阳史创编 2021..02.10
欧阳史创编 2021..02.10
If (ret) Then '
' MsgBox \"找到卡,正在读卡...\"
' ret = MsgBox(\"找到卡,正在读卡...\vbOKOnly + vbInformation, \"提示\")
ret = ReadBaseInfos(iname, isex, folk, birthday, code, addr, agency, startdate, enddate) If (ret) Then
' MsgBox \"读卡成功!\" '姓名
Range(\"a1\") = Trim(iname) '性别
Range(\"a2\") = Trim(isex) '民族
Range(\"a3\") = Trim(folk) '出生年
Range(\"a4\") = Left(Trim(birthday), 4) + \"年\" + Mid(Trim(birthday), 5, 2) + \"月\" + Mid(Trim(birthday), 7, 2) + \"日\"
Range(\"b4\") = Trim(birthday) '住址
Range(\"a5\") = Trim(addr) '公民身份号码
欧阳史创编 2021..02.10
欧阳史创编 2021..02.10
Range(\"a6\") = Trim(code) '签发机关
Range(\"a7\") = Trim(agency) '有效期限
Range(\"a8\") = Trim(enddate) If Trim(enddate) = \"长期\" Then
Range(\"b8\") = Left(Trim(startdate), 4) + \".\" + Mid(Trim(startdate), 5, 2) + \".\" + Mid(Trim(startdate), 7, 2) + \"长期\" Else
Range(\"b8\") = Left(Trim(startdate), 4) + \".\" + Mid(Trim(startdate), 5, 2) + \".\" + Mid(Trim(startdate),
7,
2)
+
\"\"
+
Left(Trim(enddate), 4) + \".\" + Mid(Trim(enddate), 5, 2) + \".\" + Mid(Trim(enddate), 7, 2) End If '显示照片
'Pic.Picture = LoadPicture(App.Path + \"\\photo.bmp\") Else
MsgBox \"读卡不成功!请重新开始读卡。\" End If
欧阳史创编 2021..02.10
欧阳史创编 2021..02.10
Else
MsgBox \"未找到卡!请将卡远离后再置于机具上。\"
End If
ret = CloseComm() End Sub
时间:2021.02.10 创作:欧阳史 欧阳史创编 2021..02.10
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- jqkq.cn 版权所有 赣ICP备2024042794号-4
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务