高分求助vsview7+vsflex结合打印的例子
高分求助vsview7+vsflex结合打印的例子
不要安装文件自带的,要求有表格,页眉,页脚
问题点数:100、回复次数:3Top
1 楼caliphliao(老九)回复于 2003-06-02 15:54:59 得分 20
Private Sub RenderRecordset(pView As VSPrinter, Rs As Recordset, ByVal maxh As Double)
Dim Arr, i%, j%, wid!
' read recordset into an array
Rs.MoveLast
Rs.MoveFirst
i = Rs.RecordCount
If i = 0 Then Exit Sub
Arr = Rs.GetRows(i)
' create table header and dummy format
Dim fmt$, hdr$
Dim fldList As Variant
fldList = SplitString(GetFldCaption(Rs))
For i = 0 To Rs.Fields.Count - 1
If i > 0 Then hdr = hdr & "|"
fmt = fmt & "|"
hdr = hdr & fldList(i)
fmt = fmt & 500
Next
' create table
pView.StartTable
pView.AddTableArray fmt, hdr, Arr
' format table
For i = 0 To Rs.Fields.Count - 1
' right-align numbers and dates
Select Case Rs.Fields(i).Type
Case 5 '數據型
pView.TableCell(tcColAlign, , i + 1) = taRightMiddle
Case Else
pView.TableCell(tcColAlign, , i + 1) = ttaLeftMiddle
End Select
' set column width
If Rs.Fields(i).Type = dbMemo Then
pView.TableCell(tcColWidth, , i + 1) = "2.5in"
Else
fmt = ""
For j = 0 To UBound(Arr, 2)
If j > 100 Then Exit For
If Len(fmt) < Len(Arr(i, j)) Then
fmt = Arr(i, j)
End If
Next
If Len(fldList(i)) > Len(fmt) Then
fmt = fldList(i)
End If
pView.TableCell(tcColWidth, , i + 1) = pView.TextWidth(fmt) * 2
End If
Next
' format header row (0)
pView.TableCell(tcFontBold, 0) = True
pView.TableCell(tcBackColor, 0) = vbYellow
pView.TableCell(tcRowHeight, 0) = pView.TextHeight("Test") * 1.1
pView.TableCell(tcAlign, 0) = taLeftMiddle
' make sure it all fits
For i = 1 To pView.TableCell(tcCols)
wid = wid + pView.TableCell(tcColWidth, , i)
Next
pView.GetMargins
If wid > pView.X2 - pView.X1 Then
wid = (pView.X2 - pView.X1) / wid * 0.95
For i = 1 To pView.TableCell(tcCols)
pView.TableCell(tcColWidth, , i) = wid * pView.TableCell(tcColWidth, , i)
Next
End If
' honor maximum row height
If maxh > 0 Then
For i = 1 To pView.TableCell(tcRows)
If pView.TableCell(tcRowHeight, i) > maxh Then
pView.TableCell(tcRowHeight, i) = maxh
End If
Next
End If
' done with table
pView.EndTable
End Sub
Public Sub vReport(Rs As ADODB.Recordset)
'
' record source changed, get new recordset and render it
'
MousePointer = vbHourglass
' get record source string (trim comments up to ":")
' Dim s$, i%
' s = cmbSource
' i = InStr(s, ":")
' If i > 0 Then s = Trim(Mid(s, i + 1))
' get recordset
' create document
With pView
' set up
.FontName = "Tahoma"
.FontSize = 9
.PenColor = RGB(190, 190, 190)
.Footer = "有限公司|Page %d"
' .PageBorder = pbColBottom '底線
.StartDoc
' show title
.Paragraph = "標題"
.FontBold = True
.FontBold = False
.Paragraph = ""
' render recordset (this is the main routine here)
RenderRecordset pView, Rs, 0
' done
.EndDoc
.ScrollIntoView 0, 0
End With
MousePointer = vbDefault
End Sub
Private Sub Form_Load()
pView.MarginLeft = 60
pView.MarginBottom = 1440
pView.MarginRight = 60
pView.MarginTop = 1440
End Sub
Private Sub Form_Resize()
pView.Height = ScaleHeight - 20
pView.Top = 10
pView.Left = 10
pView.Width = ScaleWidth - 20
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo Form_Unload_Err
Set FrmPrint = Nothing
Exit Sub
Form_Unload_Err:
MsgBox Me.Caption & "|Form_Unload:" & Err.Description, vbOKOnly + vbCritical, CStr(Err.Number)
End Sub
Top
2 楼lihonggen0(李洪根,MS MVP,标准答案来了)回复于 2003-06-02 17:32:10 得分 10
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=39769Top
3 楼verystudy(大度)回复于 2003-06-02 23:07:14 得分 70
With pView
.FontName = "Tahoma"
.FontSize = 9
.PenColor = RGB(190, 190, 190)
.Footer = "有限公司|Page %d"
' .PageBorder = pbColBottom '底線
.StartDoc
' show title
.Paragraph = "標題"
.penrender=vsflexgrid
' done
.EndDoc
Top




