机房收费系统之查看上机记录

         在学习查看上机记录的时候,遇到了一些问题,现在都整理好了,想和大家分享一下。

         这一块是导出excel表格的部分,大家肯定也总结了不少这部分的知识点,下面话不多说,请看代码。

        If txtCardNo.Text = "" Then
              MsgBox "卡号不能为空", vbOKOnly + vbExclamation, "警告"
              txtCardNo.SetFocus
      
       Else
      If Not IsNumeric(Trim(txtCardNo.Text)) Then
             MsgBox "请输入数字", vbOKOnly + vbExclamation, "警告"
             txtCardNo.Text = ""
             txtCardNo.SetFocus
      Else
         txtSQL = "select * from student_Info where cardno='" & txtCardNo.Text & "'"
         Set mrc = ExecuteSQL(txtSQL, MsgText)
    If mrc.EOF = True Then
            MsgBox "此卡号不存在", vbOKOnly + vbExclamation, "警告"
            txtCardNo.Text = ""
            txtCardNo.SetFocus
    Else
    
        txtSQL = "select * from Line_Info where cardno='" & Trim(txtCardNo.Text) & "'"
        Set mrc = ExecuteSQL(txtSQL, MsgText)
    If mrc.EOF = False Then
        With MSHFlexGrid1
    Do While mrc.EOF = False
       .CellAlignment = 4
       
       .TextMatrix(.Rows - 1, 0) = mrc.Fields(1)
       .TextMatrix(.Rows - 1, 1) = mrc.Fields(3)
       .TextMatrix(.Rows - 1, 2) = mrc!ondate
       .TextMatrix(.Rows - 1, 3) = mrc!OnTime
       .TextMatrix(.Rows - 1, 4) = mrc!offdate
       .TextMatrix(.Rows - 1, 5) = mrc!offtime
       .TextMatrix(.Rows - 1, 6) = mrc!consume
       .TextMatrix(.Rows - 1, 7) = mrc!cash
    mrc.MoveNext
    Loop
    End With

上面部分是未导出之前的查看记录显示代码。

    Dim xlApp As New Excel.Application        '声明Excel对象
    Dim xlBook As Excel.Workbook              '声明工作簿对象
    Dim xlSheet As Excel.Worksheet            '声明工作表单
    Dim i As Integer
    Dim j As Integer
    
    If MSHFlexGrid1.Text = "" Then            '判断是否有记录可以导出
        MsgBox "没有记录可导出!", vbOKOnly + vbExclamation, "警告"
        Exit Sub
    Else
        Set xlApp = CreateObject("excel.application")     '调用execel程序
        Set xlBook = xlApp.Workbooks.Add(1)               '创建新的空白簿
        Set xlSheet = Excel.ActiveWorkbook.ActiveSheet    '创建新的工作表单
            For i = 0 To MSHFlexGrid1.Rows - 1            '填入数据
            For j = 0 To MSHFlexGrid1.Cols - 1
                xlSheet.Cells(i + 1, j + 1) = MSHFlexGrid1.TextMatrix(i, j)        'cell(a,b)表示a行,b列
            Next j
            Next i
        xlApp.Visible = True         '显示Excel表格
        Set xlApp = Nothing          '交还控制给Excel
    End If

  这一部分是导出excel表格的代码部分。

  希望对大家有帮助!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值