梦想鸭来拿你想要的东西啊
Private Sub Dy()
With Rs
.MoveLast
ReDim strDy(.RecordCount + 8)
ReDim Fmt(.Fields.Count)
For I = 0 To .RecordCount + 7
strDy(I) = "" '初始化
Next
For I = 0 To .Fields.Count - 1
Fmt(I) = getFmt(.Fields(I).Type, CInt(.Fields(I).Size))
J = lstrlen(.Fields(I).Name & Chr(0))
If J > lstrlen(Fmt(I) & Chr(0)) Then
Fmt(I) = String(J, "@")
End If
Next
str = "┃"
str0 = "┏"
str1 = "┠"
str2 = "┗"
For I = 0 To .Fields.Count - 1
For J = 1 To Len(Fmt(I)) / 2
str0 = str0 & "━"
str1 = str1 & "─"
str2 = str2 & "━"
Next
'为减小宽度而采取以下办法
'If Len(Fmt(I)) > 40 Then
length = Len(Fmt(I)) - lstrlen(.Fields(I).Name)
If (I = .Fields.Count - 1) Then
str = str & String(Int(length / 2), " ") & .Fields(I).Name & String(Int(length / 2), " ") & "┃"
str0 = str0 & "┓"
str1 = str1 & "┨"
str2 = str2 & "┛"
Else
str = str & String(Int(length / 2), " ") & .Fields(I).Name & String(Int(length / 2), " ") & "│"
str0 = str0 & "┯"
str1 = str1 & "┼"
str2 = str2 & "┷"
End If
Next
Title = "岳阳汉森产业有限公司考勤日报表"
strDy(0) = Space(18) & Title
strDy(1) = ""
strDy(2) = Space(30) & "打印日期:" & Date
strDy(3) = str0
strDy(4) = str
strDy(5) = str1
intDc = 6
.MoveFirst
Do While Not .EOF
str = "┃"
For I = 0 To .Fields.Count - 1
If IsNull(.Fields(I).Value) Then
If (I = .Fields.Count - 1) Then
str = str & Format(" ", Fmt(I)) & "┃"
Else
str = str & Format(" ", Fmt(I)) & "│"
End If
Else
length = Len(Fmt(I)) - lstrlen(.Fields(I).Value)
If (I = .Fields.Count - 1) Then
str = str & String(length, " ") & .Fields(I).Value & "┃"
Else
str = str & String(length, " ") & .Fields(I).Value & "│"
End If
End If
Next
strDy(intDc) = strDy(intDc) & str
intDc = intDc + 1
.MoveNext
Loop
strEnd = strEnd & str2
End With
End Sub
Private Function getFmt(intType As Integer, logSize As Long) As String
Dim I As Integer
getFmt = ""
Select Case intType
Case dbBoolean
getFmt = getFmt & "\ \ \ \0;\ \ \ \1"
Case dbByte
getFmt = "@@@@"
Case dbInteger
getFmt = "@@@@@@"
Case dbLong
getFmt = "@@@@@@@@@@"
Case dbCurrency
getFmt = "@@@@@@@@@@"
Case dbSingle
getFmt = "@@@@@@@@@@"
Case dbDouble
getFmt = "@@@@@@@@@@"
Case dbDate
getFmt = "@@@@@@@@@@"
Case dbBinary
getFmt = "@@@@"
Case dbText
If logSize >= 20 Then
getFmt = String(12, "@")
Else
getFmt = String(Int((logSize + 1) / 2) * 2, "@")
End If
Case dbLongBinary
getFmt = "@@@@"
Case dbMemo
getFmt = "@@@@@@@@@@@@@@@@"
Case dbGUID
getFmt = "@@@@"
Case dbBigInt
getFmt = "@@@@@@@@@@@@@@"
Case dbVarBinary
getFmt = "@@@@"
Case dbChar
For I = 0 To CInt(logSize / 2) * 2 - 1
getFmt = getFmt & "@"
Next
Case dbNumeric
For I = 0 To CInt(logSize / 2) * 2 - 1
getFmt = getFmt & "@"
Next
Case dbDecimal
For I = 0 To CInt(logSize / 2) * 2 - 1
getFmt = getFmt & "@"
Next
Case dbFloat
getFmt = "@@@@@@@@@@"
Case dbTime
getFmt = "@@@@@@@@"
Case dbTimeStamp
getFmt = "@@@@@@@@@@"
End Select
End Function
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Index
Case 1 '打印
Printer.Font.Name = "楷体GB-2312"
Printer.Font.Size = 8
Printer.Font.Bold = True
Printer.Print Space(80) & strHead '打页眉
Printer.Line (0, 190)-(Me.Width, 190)
Printer.Print strDy(1) '打空行
Printer.Font.Bold = False
Printer.Font.Name = "隶书"
Printer.Font.Size = 18
Printer.Print strDy(0) '打印标题
Printer.Print strDy(1) '打印空行
Printer.Font.Name = "楷体GB-2312"
Printer.Font.Size = 14
Printer.Print strDy(2) '打印日期
Printer.Print strDy(1) '打印空行
For I = 1 To Form13.intLength '打印汇总情况
Printer.Print strHZ(I)
Printer.Print strDy(1) '打印空行
Next
Printer.Font.Name = "黑体"
Printer.Print Space(10) & "附:未正常出勤人员明细表"
intCount = 6
Printer.Font.Name = "楷体GB-2312"
'在第一页中打印表格内容
Printer.Font.Name = "宋体"
Printer.Font.Size = 12
Printer.Print Space(10) & strDy(3) '打印表头
Printer.Print Space(10) & strDy(4)
'确定每页打印表格行数
intTemp = 27 - (Form13.intLength - 1) * 4
For I = intCount To intTemp
Printer.Print Space(10) & strDy(5)
Printer.Print Space(10) & strDy(I) '打印表格内容
Next
Printer.Print Space(10) & strEnd '打印表尾
Printer.Print strDy(1)
Printer.Print Space(50) & "第" & Printer.Page & "页 " & Format(Date, "yyyy年mm月dd日") '打印页码
Printer.NewPage
intCount = I
Start1:
Printer.Font.Name = "宋体"
Printer.Font.Size = 12
Printer.Print strDy(1) '打印空行
Printer.Print Space(10) & strDy(3) '打印表头
Printer.Print Space(10) & strDy(4)
For I = intCount To intDc
If I < intCount + 28 And I < intDc Then '如果在一页内
Printer.Print Space(10) & strDy(5)
Printer.Print Space(10) & strDy(I) '打印表格内容
Else '换页
Printer.Print Space(10) & strEnd '打印表尾
Printer.Print strDy(1)
Printer.Print Space(50) & "第" & Printer.Page & "页 " & Format(Date, "yyyy年mm月dd日") '打印页码
If I = intDc Then
Exit Sub
End If
Printer.NewPage
intCount = I
GoTo Start1
End If
Next
Printer.EndDoc
End Select
End Sub