使用VB读取EXCEL数据的小程序

使用VB读取EXCEL数据的小程序

程序界面

VB生成EXE工程时可能由于系统原因会导致按钮文字显示不全,缺字少字的情况,网上搜了好多帖子,有说DLL文件缺失,有说框体不够大等等,我全都尝试了一遍都没有解决,最后本人使用了一个比较LOW的办法:在按钮Caption属性中输入文字时多加了些空格,终于解决了

在这里插入图片描述

部分代码

代码片如下:.

    Dim excel_App As Excel.Application
    Dim excel_Book As Excel.Workbook
    Dim excel_sheet1 As Excel.Worksheet
    Dim excel_sheet2 As Excel.Worksheet
Private Sub Form_Load()

    Set excel_App = CreateObject("excel.application")
    Set excel_Book = excel_App.Workbooks.Open(App.Path + "\MD5.xls")
    Set excel_sheet1 = excel_Book.Worksheets("sheet1")
    Set excel_sheet2 = excel_Book.Worksheets("sheet2")

End Sub

Private Sub Form_Unload(Cancel As Integer)



'    关闭EXCEL
'    强制回收 Excel 进程
    
    excel_Book.Close (False) '关闭工作簿
'    int geneID = System.GC.GetGeneration(excel_App)
'    excel_App.Visible = False
    Set excel_sheet1 = Nothing
    Set excel_sheet2 = Nothing
    Set excel_Book = Nothing
    excel_App.Quit '结束EXCEL对象
    Set excel_App = Nothing '释放xlApp对象

End Sub
'D-证件号4 E-姓名5 H-秘钥8
'CStr(excel_sheet1.Cells(2, 4))
'CStr(excel_sheet1.Cells(2, 5))
'CStr(excel_sheet1.Cells(2, 8))
's_MD5str = Module_MD5.MD5("ABC", 32)

Private Sub MD5_Click()

'    重复部分
    Dim strxml_templ As String

    strxml_templ = strxml_templ + "IdentNo" + "&"
    strxml_templ = strxml_templ + "ChinNm" + "|"

    
'   循环读取表格参数后进行拼接
    Dim flag As Integer
    Dim strxml_rebody As String
    strxml_rebody = strxml_templ
    flag = 2
    
    For i = 1 To 300
        strxml_rebody = strxml_templ
        strxml_rebody = Replace(strxml_rebody, "IdentNo", CStr(excel_sheet1.Cells(flag, 4)))
        strxml_rebody = Replace(strxml_rebody, "ChinNm", CStr(excel_sheet1.Cells(flag, 5)))

        strxml_body = strxml_body + strxml_rebody
        
'    逻辑判断读取行数
        flag = flag + 1
        
        If Cells(flag, 1) = "" Then
            Exit For
        End If
       
    Next i

    strxml_rebody = strxml_body + CStr(excel_sheet1.Cells(2, 8))
    
'    MsgBox strxml_rebody

    s_MD5str = Module_MD5.MD5(strxml_rebody, 32)
    
''    关闭EXCEL
'    excel_Book.Close (False) '关闭工作簿
'    excel_App.Visible = False
'    excel_App.Quit '结束EXCEL对象
'    Set excel_sheet1 = Nothing
'    Set excel_Book = Nothing
'    Set excel_App = Nothing '释放xlApp对象
End Sub

Private Sub Text1_Click()

'选中文本框中全部内容
'MsgBox "abc"
    With Text1
        .SelStart = 0
        .SelLength = Len(Text1.Text)
        '让文本框获取焦点
        .SetFocus
    End With

End Sub

Private Sub 单笔港澳台居民来往大陆通行证信息核查_Click()

'    Set excel_App = CreateObject("excel.application")
'    Set excel_Book = excel_App.Workbooks.Open(App.Path + "\MD5.xls")
'    Set excel_sheet1 = excel_Book.Worksheets("sheet1")
'    Set excel_sheet2 = excel_Book.Worksheets("sheet2")
    
'    excel_sheet2.Cells(3, 1) = "TEST"

    strxml = "<service>" + Chr(10) + Chr(13)
    
'    HEAD字符串拼接
    strxml_head = Chr(9) + "<Head>" + Chr(10) + Chr(13)
    strxml_head = strxml_head + Chr(9) + Chr(9) + "<SvcCd>" + CStr(excel_sheet2.Cells(2, 1)) + "</SvcCd>" + Chr(10) + Chr(13)
    strxml_head = strxml_head + Chr(9) + Chr(9) + "<ChanlCd>" + CStr(excel_sheet2.Cells(2, 2)) + "</ChanlCd>" + Chr(10) + Chr(13)
    strxml_head = strxml_head + Chr(9) + Chr(9) + "<Mac />" + Chr(10) + Chr(13)
    strxml_head = strxml_head + Chr(9) + Chr(9) + "<CnsmrSysNo>" + CStr(excel_sheet2.Cells(2, 3)) + "</CnsmrSysNo>" + Chr(10) + Chr(13)
    strxml_head = strxml_head + Chr(9) + Chr(9) + "<CnsmrNodeNo>" + CStr(exc
  • 3
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值