📄 frmdataout.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form FrmDataOut
Caption = "定制数据转换"
ClientHeight = 5100
ClientLeft = 60
ClientTop = 345
ClientWidth = 6885
Icon = "FrmDataOut.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 5100
ScaleWidth = 6885
StartUpPosition = 2 '屏幕中心
Begin VB.Frame Frame2
Caption = "帮助说明:"
Height = 2535
Left = 120
TabIndex = 7
Top = 120
Width = 6615
Begin VB.Label Label11
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "order by"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00008000&
Height = 210
Left = 4320
TabIndex = 17
Top = 2160
Width = 840
End
Begin VB.Label Label10
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "from"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00008000&
Height = 210
Left = 4080
TabIndex = 16
Top = 1850
Width = 420
End
Begin VB.Label Label9
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "select"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00008000&
Height = 210
Left = 720
TabIndex = 15
Top = 1850
Width = 630
End
Begin VB.Label Label8
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "{可参照帮助文件}"
Height = 180
Left = 4560
TabIndex = 14
Top = 360
Width = 1620
End
Begin VB.Label Label7
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "志表等六张数据表,各表的字段和内在联系请咨询管理员。"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 210
Left = 120
TabIndex = 13
Top = 1080
Width = 5460
End
Begin VB.Label Label6
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "本数据系统共有教师表、分工表、学籍表、成绩表、考核表和日"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 210
Left = 480
TabIndex = 12
Top = 720
Width = 5880
End
Begin VB.Label Label5
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "JOIN 学籍表 AS b ON a.考试号 = b.考试号 order by a.总分 desc"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 210
Left = 120
TabIndex = 11
Top = 2160
Width = 6300
End
Begin VB.Label Label3
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "select b.班级,b.学号,b.姓名,a.* from 成绩表 AS a INNER"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H000000C0&
Height = 210
Left = 720
TabIndex = 10
Top = 1850
Width = 5670
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "2、理解SQL语句:(举例两个表连接查询输出)"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 210
Left = 240
TabIndex = 9
Top = 1560
Width = 4410
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "1、须完全了解“教务管理系统”数据库列表:"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 210
Left = 240
TabIndex = 8
Top = 360
Width = 4305
End
End
Begin VB.Frame Frame1
Caption = "转换为Excel文件输出"
Height = 2175
Left = 120
TabIndex = 5
Top = 2760
Width = 6615
Begin VB.CommandButton Command2
Caption = "..."
Height = 375
Left = 5880
TabIndex = 18
Top = 1200
Width = 495
End
Begin MSComDlg.CommonDialog Cdlg
Left = 2760
Top = 1800
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.TextBox SqlTxt
Enabled = 0 'False
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00008000&
Height = 375
Left = 240
TabIndex = 1
Top = 720
Width = 6135
End
Begin VB.CheckBox Check1
Caption = "特殊SQL语句输出"
BeginProperty Font
Name = "楷体_GB2312"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00800000&
Height = 375
Left = 240
TabIndex = 0
Top = 240
Width = 2295
End
Begin VB.TextBox OutTxt
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 2280
TabIndex = 2
Text = "C:\表1.xls"
Top = 1200
Width = 3495
End
Begin VB.CommandButton Command1
Caption = "输出Excel文件"
Height = 375
Left = 480
TabIndex = 3
Top = 1680
Width = 1695
End
Begin VB.CommandButton Command3
Caption = "关闭"
Height = 375
Left = 3480
TabIndex = 4
Top = 1680
Width = 1095
End
Begin VB.Label Label4
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "输出文件名称:"
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 285
Left = 240
TabIndex = 6
Top = 1200
Width = 1995
End
End
End
Attribute VB_Name = "FrmDataOut"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim rs As ADODB.Recordset
Private Sub Check1_Click()
If Check1.Value = 0 Then
SqlTxt.Enabled = False
Else
SqlTxt.Enabled = True
End If
End Sub
Private Sub Command1_Click()
On Error GoTo errs
Dim ExcelApp As Excel.Application
Dim ExcelBook As Excel.Workbook
Dim ExcelSheet As Excel.Worksheet
Set ExcelApp = New Excel.Application
ExcelApp.Visible = False
Set ExcelBook = ExcelApp.Workbooks.Add
Set ExcelSheet = ExcelBook.Worksheets.Item(1)
rs.Open SqlTxt.Text, Con, , adLockPessimistic, adCmdText
RecordsetToExcel rs, ExcelSheet
If OutTxt.Text = "" Then
MsgBox "请指定输出文件位置和文件名!", 16, "严重错误"
Exit Sub
End If
On Error GoTo ErrSave
ExcelBook.Close True, OutTxt.Text
MsgBox "输出成功!文件位于" & OutTxt.Text
rs.Close
Exit Sub
errs:
MsgBox "Select 语句错误!", 16, "严重错误"
ExcelBook.Close False
Exit Sub
ErrSave:
MsgBox "输出错误!", 16, "严重错误"
End Sub
'纪录导出到Execl
Public Sub RecordsetToExcel(rs As ADODB.Recordset, excel_sheet As Excel.Worksheet)
Dim i As Long, j As Long
Dim excel_range As Excel.Range
Dim col_count As Long
If rs.RecordCount = 0 Then
Exit Sub
End If
Set excel_range = excel_sheet.Cells
col_count = rs.Fields.Count
For i = 0 To col_count - 1
excel_sheet.Cells(1, i + 1).Value = rs.Fields(i).Name
Next
excel_sheet.Range(excel_sheet.Cells(1, 1), _
excel_sheet.Cells(1, col_count)).Font.Bold = True
excel_sheet.Range("A2").CopyFromRecordset rs
End Sub
'Execl纪录导入到
Private Sub ExportExcelSheetToAccess()
End Sub
Private Sub Command2_Click()
Cdlg.DialogTitle = "另存为Excel文件:"
Cdlg.Filter = "Excel文件|*.Xls|所有文件|*.*"
Cdlg.ShowSave
If Cdlg.FileName = "" Then Exit Sub
OutTxt.Text = Cdlg.FileName
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Command4_Click()
Dim TableName As String
If Combo1.ListIndex = -1 Then
MsgBox "请选择数据库", 16, "严重错误"
Exit Sub
Else
Select Case Combo1.ListIndex
Case 0
TableName = teacher
Case 1
TableName = student
Case 2
TableName = course
Case 3
TableName = kteacher
Case 4
TableName = logtxt
End Select
End If
If TxtIn.Text = "" Or Dir(TxtIn.Text) = "" Then
MsgBox "没有发现Excel文件!", 16, "严重错误"
Exit Sub
End If
ExportExcelSheetToAccess
End Sub
Private Sub Form_Load()
Set rs = New ADODB.Recordset
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -