📄 -
字号:
Dim sRTitle As String '标题
Dim iShowAllCols As Integer '1 显示所有可见网格列
s = "select * from PM_ReportSort where RCode='" & sRCode & "'"
Set rs = Cw_DataEnvi.DataConnect.Execute(s)
With rs
If Not .EOF() Then
iPrintStyle = !PrintStyle
iSumPerPage = !SumPerPage
iSplitPage = !SplitPage
iShowAllCols = !ShowAllCols
sRTitle = Trim(!RTitle)
Else
MsgBox "当前报表已被删除,无法读取格式!", vbOKOnly + vbCritical
Exit Function
End If
End With
Set rs = Nothing
'--------------------------------------------------控制信息完成-------------------------------------------------
'--------------------------------------------------打印参数-------------------------------------------------
'设置打印参数
If Not SetupPage(frmSetup, DY_Tybbyldy) Then
MsgBox "打印设置失败!", vbOKOnly + vbCritical
Exit Function
End If
'读取打印设置
Dim sDataFontName As String '数据字体名称
Dim sTitleFontName As String '表头字体名称
Dim iDataFontSize As Long '数据字体大小
Dim iTitleFontSize As Long '表头字体大小
Dim iRowsPerPage As Long '每行显示数据行数
Dim bLimitRowPerPage As Boolean '是否每页限制行数
Dim iLimitRowsPerPage As Long '每页限制行数
Dim iClientHeight As Long '页面可用高度
Dim iPageLeft As Long '左边界
Dim iClientWidth As Long '页面可用宽度
Dim iPageTop As Long '上边界
Dim iTitleFontHeight As Long '标题高度
Dim iDataFontHeight As Long '数据高度
With frmSetup
sTitleFontName = .Btztlabel.Caption
sDataFontName = .SjztLabel.Caption
iTitleFontSize = Val(.Btzhlabel.Caption)
iDataFontSize = Val(.Sjzhlabel.Caption)
bLimitRowPerPage = .ZdhsCheck.Value
iLimitRowsPerPage = Val(.BbhsText)
End With
With DY_Tybbyldy.Tydy
.StartDoc
.FontName = sTitleFontName
.FontSize = iTitleFontSize
.CalcText = "测试"
iTitleFontHeight = .TextHei
.FontName = sDataFontName
.FontSize = iDataFontSize
.CalcText = "测试"
iDataFontHeight = .TextHei
.EndDoc
.KillDoc
iPageHeight = .PageHeight
iClientHeight = .PageHeight - .MarginBottom - .MarginTop
iPageTop = .MarginTop
iClientWidth = .PageWidth - .MarginLeft - .MarginRight
iPageLeft = .MarginLeft
End With
'--------------------------------------------------打印参数完成-------------------------------------------------
'--------------------------------------------------读取数据信息-------------------------------------------------
'定义打印开始列
If iShowAllCols = 1 Then
iStartCol = iVsBeginCol
Else
iStartCol = iVsSumEndCol + 1
End If
'读取有效数据
Dim sData() As String '网格表体数据
Dim sTitle() As String '表头数据
Dim iPages() As Long '打印分页信息,第i页结束行在sData()中的位置是iPages(i)
Dim iTitleRows() As String '打印的表头行值
Dim iDataRows() As String '打印的数据行值
Dim iColsPerPage() As Long '每行在页面上的折行信息 第i行的结束列对应sData()中的iColsPerPage(i)列
Dim iCols() As Long '需要打印的列值
Dim iColWidth() As Long '需要打印的列款
Dim iColType() As Long '需要打印的列数据类型
Dim iColFormat() As String '需要打印的列格式
With vs
'读取有效列
ReDim iCols(0)
iCols(0) = 0
ReDim iColWidth(0)
iColWidth(0) = 0
ReDim iColType(0)
iColType(0) = 0
ReDim iColFormat(0)
iColFormat(0) = ""
For i = 0 To .Cols - 1
If Not .ColHidden(i) Then
ReDim Preserve iCols(UBound(iCols) + 1)
iCols(UBound(iCols)) = i
ReDim Preserve iColWidth(UBound(iColWidth) + 1)
If .ColWidth(i) >= iClientWidth Then
MsgBox "纸张宽度太小不能输出报表,请重新设置!", vbOKOnly + vbCritical
Exit Function
End If
iColWidth(UBound(iColWidth)) = .ColWidth(i)
ReDim Preserve iColType(UBound(iColType) + 1)
iColType(UBound(iColType)) = Val(.TextMatrix(0, i))
ReDim Preserve iColFormat(UBound(iColFormat) + 1)
iColFormat(UBound(iColFormat)) = .ColFormat(i)
End If
Next i
If UBound(iCols) = 0 Then
Exit Function
End If
'读取有效表头行
ReDim iTitleRows(0)
iTitleRows(0) = 0
For i = 0 To .FixedRows - 1
If .RowHidden(i) = False Then
ReDim Preserve iTitleRows(UBound(iTitleRows) + 1)
iTitleRows(UBound(iTitleRows)) = i
End If
Next i
If UBound(iTitleRows) = 0 Then
Exit Function
End If
'读取有效数据行
ReDim iDataRows(0)
iDataRows(0) = 0
For i = .FixedRows To .Rows - 1
If .RowHidden(i) = False Then
ReDim Preserve iDataRows(UBound(iDataRows) + 1)
iDataRows(UBound(iDataRows)) = i
End If
Next i
If UBound(iDataRows) = 0 Then
Exit Function
End If
'读取表头数据
ReDim sTitle(UBound(iTitleRows) - 1, UBound(iCols) - 1)
For i = LBound(iTitleRows) + 1 To UBound(iTitleRows)
For j = LBound(iCols) + 1 To UBound(iCols)
sTitle(i - LBound(iTitleRows) - 1, j - LBound(iCols) - 1) = .TextMatrix(iTitleRows(i), iCols(j))
Next j
Next i
'读取表体数据
ReDim sData(UBound(iDataRows) - 1, UBound(iCols) - 1)
For i = LBound(iDataRows) + 1 To UBound(iDataRows)
For j = LBound(iCols) + 1 To UBound(iCols)
sData(i - LBound(iDataRows) - 1, j - LBound(iCols) - 1) = .TextMatrix(iDataRows(i), iCols(j))
Next j
Next i
'--------------------------------------------------读取数据信息完成-------------------------------------------------
'--------------------------------------------------计算打印信息-------------------------------------------------
'计算数据行折行信息
ReDim iColsPerPage(0)
iColsPerPage(0) = iStartCol
Dim iWidth As Long
iWidth = 0
For i = LBound(iColWidth) + 1 + iStartCol To UBound(iColWidth)
iWidth = iWidth + iColWidth(i)
If iWidth > iClientWidth Then
iWidth = 0
i = i - 1
ReDim Preserve iColsPerPage(UBound(iColsPerPage) + 1)
iColsPerPage(UBound(iColsPerPage)) = i
End If
Next i
If iWidth <> 0 Then
ReDim Preserve iColsPerPage(UBound(iColsPerPage) + 1)
iColsPerPage(UBound(iColsPerPage)) = UBound(sData, 2) + 1
End If
'计算每页可以打印的行数
If iSumPerPage = 1 Then
i = 1
Else
i = 0
End If
j = UBound(sTitle) + 2
If iPrintStyle = PRINTSTYLE_ONETITLE Then
iRowsPerPage = (iClientHeight - iTitleFontHeight - iDataFontHeight - 1000) \ (UBound(iColsPerPage) * (iDataFontHeight + 100)) - i
Else
j = UBound(sTitle) + 2
iRowsPerPage = (iClientHeight - iTitleFontHeight - iDataFontHeight - 1000) \ (UBound(iColsPerPage) * j * (iDataFontHeight + 250)) - i
End If
If bLimitRowPerPage = True Then
If iRowsPerPage > iLimitRowsPerPage Then
iRowsPerPage = iLimitRowsPerPage
End If
End If
'计算分页信息
ReDim iPages(0)
iPages(0) = -1
If iVsSumEndCol = -1 Or iSplitPage = 0 Then '如果没有分页情况,只需判断本页最多能够打印的行数
For i = LBound(sData) To UBound(sData)
If i Mod iRowsPerPage = iRowsPerPage - 1 Then
ReDim Preserve iPages(UBound(iPages) + 1)
iPages(UBound(iPages)) = i
End If
Next i
Else
'如果有分页情况,则首先判断是否是分页行,然后循环判断下边的行
'如果是合计行则加入本页(在数据行数小于可打印行数的情况下)
For i = LBound(sData) To UBound(sData) '数据行数达到最大行
If (i - iPages(UBound(iPages))) Mod iRowsPerPage = 0 And i <> 0 Then
ReDim Preserve iPages(UBound(iPages) + 1)
iPages(UBound(iPages)) = i
If Len(sData(i, iVsSumEndCol)) >= 3 Then
s = Right(sData(i, iVsSumEndCol), 3)
Else
s = ""
End If
If s = "合计:" Or s = "小计:" Then
bSumRow = True
End If
Else '合计分行
If Len(sData(i, iVsSumEndCol)) >= 3 Then
s = Right(sData(i, iVsSumEndCol), 3)
Else
s = ""
End If
If s = "合计:" Or s = "小计:" Or bSumRow = True Then
bNext = False
bSumRow = False
For j = iVsSumEndCol To iVsBeginCol + 1 Step -1
If Len(sData(i + 1, j - 1)) >= 3 Then
s = Right(sData(i + 1, j - 1), 3)
Else
s = ""
End If
If s = "合计:" Or s = "小计:" Then
bNext = True
i = i + 1
'如果当前行达到最大行,分页
If (i - iPages(UBound(iPages))) Mod iRowsPerPage = 0 Then
ReDim Preserve iPages(UBound(iPages) + 1)
iPages(UBound(iPages)) = i
bNext = False
End If
End If
Next j
'因为如果bNext=true 则数据行多移动了一行,减去
If bNext = True Then
i = i - 1
End If
'判断起始列的合计情况
bNext = False
Do While True
If i < UBound(sData) Then
If Len(sData(i + 1, iVsBeginCol)) >= 3 Then
s = Right(sData(i + 1, iVsBeginCol), 3)
Else
s = ""
End If
If s = "小计:" Or s = "合计:" Then
i = i + 1
bNext = True
Else
Exit Do
End If
Else
Exit Do
End If
Loop
If bNext = True Then
ReDim Preserve iPages(UBound(iPages) + 1)
iPages(UBound(iPages)) = i
End If
End If
End If
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -