有这个工夫,用Printer对象早打出来了,决对可以精确定位,完全控制任何一个细节。
这是我才用的一段代码:
Dim asngColWidth(0 To 9) As Single '表格各列的宽度
asngColWidth(0) = 15#: asngColWidth(1) = 24#
asngColWidth(2) = 31#: asngColWidth(3) = 10#
asngColWidth(4) = 15#: asngColWidth(5) = 19#
asngColWidth(6) = 22#: asngColWidth(7) = 16#
asngColWidth(8) = 18#: asngColWidth(9) = 18#
Private Sub PrintXY(oDest As Object, X As Single, Y As Single, strText As String)
oDest.CurrentX = X
oDest.CurrentY = Y
oDest.Print strText
End Sub
'以MM为单位
'X,Y 所画表格的位置,RowCnt 表格的行数,RowHeight 表格的行高,ColWidths()数组,存放每一列的列宽
Private Sub DrawTable(oDest As Object, X As Single, Y As Single, RowCnt As Long, RowHeight As Single, ColWidths() As Single)
Dim sngTableW As Single
Dim sngTableH As Single
Dim lngLoop As Long
Dim lngColCnt As Long
lngColCnt = UBound(ColWidths)
For lngLoop = 0 To lngColCnt
sngTableW = sngTableW + ColWidths(lngLoop)
Next lngLoop
sngTableH = RowCnt * RowHeight
'画表格外边框,用粗线
oDest.DrawWidth = 2
oDest.Line (X, Y)-Step(sngTableW, sngTableH), , B
'画表格内部线条,用细线
oDest.DrawWidth = 1
'画横线
For lngLoop = 1 To RowCnt - 1
oDest.Line (X, Y + lngLoop * RowHeight)-Step(sngTableW, 0)
Next lngLoop
'画竖线
Dim sngXPos As Single
sngXPos = X
For lngLoop = 0 To lngColCnt - 1
sngXPos = sngXPos + ColWidths(lngLoop)
oDest.Line (sngXPos, Y)-Step(0, RowCnt * RowHeight)
Next lngLoop
End Sub
Private Function GetXPosInCell(CellWidth As Single, TextWidth As Single, Align As String) As Single
Select Case Align
Case "C"
GetXPosInCell = (CellWidth - TextWidth) / 2
Case "L"
GetXPosInCell = 1
Case "R"
GetXPosInCell = CellWidth - TextWidth - 1
End Select
End Function
Private Sub PrintInCellXY(oDest As Object, Y As Single, CellLeft As Single, CellWidth As Single, ByVal strText As String, strAlign As String)
Dim sngCellXpos As Single
Dim sngTextWidth As Single
If strAlign = "R" Then strText = Format(strText, "0.00")
sngTextWidth = oDest.TextWidth(strText)
Select Case strAlign
Case "C"
sngCellXpos = (CellWidth - sngTextWidth) / 2
Case "L"
sngCellXpos = 1
Case "R"
sngCellXpos = CellWidth - sngTextWidth - 1
End Select
sngCellXpos = sngCellXpos + CellLeft
oDest.CurrentX = sngCellXpos
oDest.CurrentY = Y
oDest.Print strText
End Sub