'======================================================================================================
strTxtName = "F" & Right("00" & i, 2) ' oPrintGrid.Columns(I).DataField
Set FldCtrl = GsReportModel.Sections("Detail").Controls.Add("DDActiveReports2.Field") '添加字段
With FldCtrl
If strColPrams(11, i) = "1" Then '翻译
.Tag = strColPrams(9, i)
End If
.Visible = True
.Font.Name = "宋体"
.Font.Size = 9
.MultiLine = CBool(Abs(Val(strColPrams(5, i))))
.Name = strTxtName
.DataField = strColPrams(9, i) 'strTxtName '绑定字段名
If strColPrams(12, i) <> "" Then '固定值
.Text = strColPrams(12, i)
End If
.Alignment = strColPrams(10, i) ' oPrintGrid.Columns(i).Alignment
.VerticalAlignment = ddTXMiddle
.OutputFormat = strColPrams(7, i) 'oPrintGrid.Columns(i).NumberFormat
.Top = 0
.Left = lngLeft
.Width = strColPrams(8, i) ' oPrintGrid.Columns(i).Width
.Height = 375
.Border.BottomStyle = ddBLSolid
.Border.LeftStyle = ddBLSolid
If intShow = UBound(sPrint) - 1 Then
.Border.RightStyle = ddBLSolid
End If
If (UBound(sGroup) <= 0 Or UBound(sSubTotal)) <= 0 And (UBound(sTotal) <= 0) Then
lngLeft = lngLeft + .Width
End If
End With
'===============小计========================================================
If UBound(sGroup) > 0 And UBound(sSubTotal) > 0 Then
If i = 0 Then
GsReportModel.Sections("GroupHeader2").DataField = sGroup(0) ' oPrintGrid.GroupColumns(0).DataField
End If
Set FldCtrl = GsReportModel.Sections("GroupFooter2").Controls.Add("DDActiveReports2.Field") '添加字段
With FldCtrl
.Visible = True
.Font.Name = "宋体"
.Font.Size = 9
.BackColor = &HE0E0E0
.BackStyle = 1
.MultiLine = False
.Alignment = strColPrams(10, i) ' oPrintGrid.Columns(i).Alignment
.VerticalAlignment = ddTXMiddle
.OutputFormat = strColPrams(7, i) ' oPrintGrid.Columns(i).NumberFormat
.Top = 0
.Left = lngLeft
.Width = strColPrams(8, i) ' oPrintGrid.Columns(i).Width
.Height = 375
.Border.BottomStyle = ddBLSolid
.Border.LeftStyle = ddBLSolid
If intShow = UBound(sPrint) - 1 Then
.Border.RightStyle = ddBLSolid
End If
If UBound(sSubTotal) > 0 Then
For X = 0 To UBound(sSubTotal) - 1
If UCase(sSubTotal(X)) = UCase(strColPrams(9, i)) Then
.DataField = sSubTotal(X)
.SummaryGroup = "GroupHeader2"
.SummaryRunning = ddSRGroup
.SummaryType = ddSMSubTotal
Else
If intShow = 0 Then
.Text = "小计"
Else
.Text = ""
End If
End If
Next X
End If
If UBound(sTotal) <= 0 Then
lngLeft = lngLeft + .Width
End If
End With
End If
'===========================================================================
'======================================合计=================================
If UBound(sTotal) > 0 Then
Set FldCtrl = GsReportModel.Sections("ReportFooter").Controls.Add("DDActiveReports2.Field") '添加字段
With FldCtrl
.Visible = True
.Font.Name = "宋体"
.Font.Size = 9
' .ForeColor = vbRed
.BackColor = &HE0E0E0
.BackStyle = 1
.MultiLine = False
.Alignment = strColPrams(10, i) ' oPrintGrid.Columns(i).Alignment
.VerticalAlignment = ddTXMiddle
.OutputFormat = strColPrams(7, i) ' oPrintGrid.Columns(i).NumberFormat
.Top = 0
.Left = lngLeft
.Width = strColPrams(8, i) ' oPrintGrid.Columns(i).Width
.Height = 375
' .Border.BottomStyle = ddBLSolid
' .Border.LeftStyle = ddBLSolid
' If i = oPrintGrid.Columns.Count - 1 Then
' .Border.RightStyle = ddBLSolid
' End If
' If UBound(strTotal) > 0 Then
For X = 0 To UBound(sTotal) - 1
If UCase(sTotal(X)) = UCase(strColPrams(9, i)) Then
.DataField = sTotal(X)
' .SummaryGroup = "GroupHeader1"
.SummaryRunning = ddSRAll
.SummaryType = ddSMGrandTotal
Else
If intShow = 0 Then
.Text = "合计"
Else
.Text = ""
End If
End If
Next X
' End If
lngLeft = lngLeft + .Width
End With
End If
intShow = intShow + 1
'===========================================================================
Hnext:
Next i
GsReportModel.Line1.X2 = lngLeft
GsReportModel.Line2.X2 = lngLeft
Call SetSetting
' ShowReport GsReportModel
DoEvents
GsReportModel.Show vbModal
Call ReleaseRpt(GsReportModel)
Exit Sub
ErrH:
Err.Clear
Resume Next
'</EhFooter>
End Sub
Public Sub SetGridToReport(oPrintGrid As TrueOleDBGrid80.tDBgrid, sAdoSource As String, strColPrams() As Variant, sGroup() As String, _
sTotal() As String, sSubTotal() As String, sGroup2() As String, sGroup3() As String, sPrint() As String)
' adoGrid As ADODB.Recordset, Optional SubTotalFields As String,
' Optional bSubTotal As Boolean = False, Optional TotalFields As String, Optional bTotal As Boolean = False)
'<EhHeader>
On Error GoTo ErrH
'</EhHeader>
Dim adoRsRpt As ADODB.Recordset
Dim strSQL As String
Dim lblCtrl As Object
Dim i, J, X As Integer
Dim lngLeft As Long
Dim FldCtrl As Object
Dim strFldName As String
Dim strLbName As String
Dim strTxtName As String
Dim lngGroupLeft As Long
Dim intShow As Integer
lngLeft = 0
lngGroupLeft = 0
intShow = 0
Set GsReportModel.objGrid = oPrintGrid
GsReportModel.AdoDC.ConnectionString = GSG_DBConn.GStrGetConn
GsReportModel.AdoDC.Source = sAdoSource
J = 0
If UBound(sGroup) <= 0 Then
GsReportModel.Sections("PageHeader").Height = GsReportModel.Sections("PageHeader").Height + 600
End If
For i = 0 To UBound(strColPrams, 2) ' oPrintGrid.ApproxCount - 1
If strColPrams(1, i) = "0" Then GoTo Hnext '不打印
If Trim(strColPrams(0, i) & "") = "" Then GoTo Hnext
'============分组=================================================
If UBound(sGroup) > 0 Then '需要分组
If J = 0 Then
GsReportModel.Sections("GroupHeader1").DataField = sGroup(J) 'oPrintGrid.GroupColumns(j).DataField
GsReportModel.Sections("GroupHeader1").KeepTogether = True
GsReportModel.Sections("GroupHeader1").GrpKeepTogether = ddGrpAll
GsReportModel.Sections("GroupHeader1").Repeat = 3
If UBound(sGroup) > 0 Then
GsReportModel.Sections("GroupHeader1").Height = 375 + (oPrintGrid.HeadLines * oPrintGrid.RowHeight)
End If
End If
If J = 0 Then
For J = 0 To UBound(sGroup) - 1 'oPrintGrid.GroupColumns.Count - 1
Set lblCtrl = GsReportModel.Sections("GroupHeader1").Controls.Add("DDActiveReports2.label")
With lblCtrl
.Visible = True
.Font.Name = "宋体"
.Font.Size = 9
' .BackColor = &HE0E0E0
' .BackStyle = 1
.Caption = sGroup2(J) & ":" ' Trim(oPrintGrid.GroupColumns(j).Caption & "") & ":" '列名称
.VerticalAlignment = ddTXMiddle
.Left = lngGroupLeft
.Top = 0
.Width = (Len(sGroup2(J)) + 1) * 200
.Height = 375
lngGroupLeft = lngGroupLeft + (Len(sGroup2(J)) + 1) * 200
End With
Set FldCtrl = GsReportModel.Sections("GroupHeader1").Controls.Add("DDActiveReports2.Field")
With FldCtrl
.Visible = True
.Font.Name = "宋体"
.Font.Size = 9
.MultiLine = False
.Name = UCase("G" & sGroup(J))
If strColPrams(12, i) <> "" Then
.Text = strColPrams(12, i)
Else
.DataField = sGroup(J) ' oPrintGrid.GroupColumns(j).DataField '绑定字段名
End If
' .Alignment = oPrintGrid.GroupColumns(j).Alignment
.VerticalAlignment = ddTXMiddle
.Top = 0
.Left = lngGroupLeft
.Width = sGroup3(J) ' oPrintGrid.Columns(i).Width
.Height = 375
lngGroupLeft = lngGroupLeft + .Width + 500
End With
Next J
End If
End If
'======================================================================================================
If UBound(sGroup) > 0 Then
Set lblCtrl = GsReportModel.Sections("GroupHeader1").Controls.Add("DDActiveReports2.label") '添加列头
Else
Set lblCtrl = GsReportModel.Sections("PageHeader").Controls.Add("DDActiveReports2.label") '添加列头
End If
With lblCtrl
.Visible = True
.Font.Name = "宋体"
.Font.Size = 9
.BackColor = &HE0E0E0
.BackStyle = 1
.MultiLine = True
.Caption = strColPrams(0, i) ' Trim(oPrintGrid.Columns(i).Caption & "") '列名称
.VerticalAlignment = ddTXMiddle
.Alignment = ddTXCenter
.Border.TopStyle = ddBLSolid
.Border.LeftStyle = ddBLSolid
.Border.BottomStyle = ddBLSolid
If intShow = UBound(sPrint) - 1 Then
.Border.RightStyle = ddBLSolid
End If
If UBound(sGroup) > 0 Then
.Top = 375
Else
.Top = 1990
End If
.Left = lngLeft
.Width = strColPrams(8, i) ' oPrintGrid.Columns(i).Width
.Height = oPrintGrid.HeadLines * oPrintGrid.RowHeight
End With
'根据情况,预先在报表上添加多个相关控件
'下面以RptTextBox控件为例
For Each Ctl In DataReport1.Sections.Item("Section1").Controls
If TypeName(Ctl) = "RptTextBox" Then
Ctl.DataField = rs.Fields.Item(0).Name '先将所有TextBox(RptTextBox) 控件绑定到某一字段
dTextCol.Add Ctl
End If
Ctl.Left = 0
Ctl.Top = 0
Ctl.Height = 400
Ctl.Width = 600
Ctl.Visible = False
Next Ctl
For i = 0 To rs.Fields.Count - 1
With dTextCol.Item(i + 1)
.Visible = True
.DataField = rs.Fields.Item(i).Name '重新绑定字段
.Left = mLeft
mLeft = .Left + .Width
'重新定位。还有Width等等比较复杂,要根据具体情况写代码判断
End With
Next i
DataReport1.Sections.Item("Section1").Height = 400