机房收费系统之查看上机记录
2018-01-14 20:40
253 查看
在学习查看上机记录的时候,遇到了一些问题,现在都整理好了,想和大家分享一下。
这一块是导出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表格的部分,大家肯定也总结了不少这部分的知识点,下面话不多说,请看代码。
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表格的代码部分。
希望对大家有帮助!相关文章推荐
- 机房收费系统之上机状态查看
- 【机房收费系统】——上机下机
- 机房收费系统登录功能的代码记录
- 机房收费系统——上机状态查询之下机
- 机房收费系统——学生充值记录
- 总结篇(2)-----第一遍机房收费系统(上机)
- 机房收费系统之查看窗体
- 机房收费系统上机之逻辑思维
- 机房收费管理系统之上机
- 《机房收费系统文档》书写记录1
- 机房收费系统-上机操作续
- 机房收费系统之——利用数组添加多条记录
- 机房收费系统之上机
- 机房收费系统登录模块代码记录
- 机房收费系统之问题记录(2)
- 机房重构之学生查看上机记录
- 机房收费系统登录模块代码记录
- 《机房收费系统文档》书写记录0
- 【机房重构】——查看上机记录、充值记录+三层+存储过程+模板方法
- 机房收费系统---将mshflexgrid控件的记录导出到excel