一、打印页前的代码改成:ReportSheet([Report], [内容文本], [内容文本])
二、问题一的解决代码:
Public Function ReportSheet(rpt As Report, _
LeftControl As Control, _
RightControl As Control, _
Optional RowsOfPage As Integer, _
Optional Style As Integer = 0, _
Optional HasColumnHeader As Boolean = True)
'On Error Resume Next
Dim intI As Integer
Dim lngTop As Long '表格上边距,即报表页眉的高度
Dim lngBottom As Long '表格下边距,报表页眉的高度 +主体节高度×每页要显示的记录数
Dim lngLeft As Long '表格左边距,第一个控件的左边距
Dim lngRight As Long '表格右边距,最后一个控件的左边距+最后一个控件的宽度
Dim lngRowHeight As Long '行高,即主体节高度
Dim lngRows As Long
Dim lngRowTop As Long
Dim lngBottomMax As Long
Dim ctl As Control
With rpt
lngRowHeight = .Section(acDetail).Height ' 行高:主体节高度
lngTop = .Section(acPageHeader).Height ' 设上边距为页面页眉高度,为防止报表没有页面页眉所以代码单独一行
If .Page = 1 Then lngTop = .Section(acHeader).Height ' lngTop + .Section(acHeader).Height 第一页再加上报表页眉高度,为防止报表没有报表页眉所以代码单独一行
lngBottomMax = .Section(acPageFooter).Height ' 页面页脚高度,为防止报表没有页面页脚所以代码单独一行
lngBottomMax = .ScaleHeight - lngBottomMax ' 报表高度减去页面页脚高度得到最大允许的下边距
End With
lngRows = Int((lngBottomMax - lngTop) / lngRowHeight) ' 当前页面能容纳的行数
If RowsOfPage > 0 Then
If RowsOfPage < lngRows Then lngRows = RowsOfPage ' 如果指定的行数不超过能容纳的行数,取指定行数
End If
lngBottom = lngTop + lngRowHeight * lngRows ' 根据行数计算表格下边距
If HasColumnHeader Then
lngRows = lngRows + 1
lngTop = lngTop - lngRowHeight
End If
lngLeft = rpt.ScaleWidth
For Each ctl In rpt.Section(acDetail).Controls
If lngLeft > ctl.Left Then lngLeft = ctl.Left ' 表格左边距
If lngRight < ctl.Left + ctl.Width Then lngRight = ctl.Left + ctl.Width ' 表格右边距
' If Style <> 1 Then rpt.Line (ctl.Left, lngTop)-(ctl.Left, lngBottom) ' 画竖线
Next
' If Style <> 1 Then rpt.Line (lngRight, lngTop)-(lngRight, lngBottom) ' 在最右边画竖线
'画横线
If Style <> 2 Then
For intI = 1 To lngRows
rpt.Line (lngLeft, lngTop + lngRowHeight * intI)-(lngRight, lngTop + lngRowHeight * intI)
Next
End If
End Function
三、问题二的方法,是调整“内容文本”文本框架的上边距和行距,我只调试了一行,都是0.199cm,高度是0.751cm。