Dim h,i,m,l,r,colscount As Integer
Dim colname As String
Dim tb As Table=Tables("" & e.Form.name & "_table1")
Dim cr As Row=Tables("打印设置").Rows(0) '打印设置表第一行
Dim doc As New PrintDoc '定义一个报表
Dim rt As New prt.RenderTable() '定义一个表格对象
Dim rs As New prt.RenderText() '定义一个文本对象
Dim rs1 As New prt.RenderText() '定义一个文本对象
'设置纸张方向
If vars("横向打印")=True
Doc.PageSetting.Landscape = True '横向打印
Else
Doc.PageSetting.Landscape = False '纵向打印
End If
m=vars("左边距")
l=vars("右边距")
Doc.PageSetting.LeftMargin = 10 '设置左边距
Doc.PageSetting.RightMargin = 10 '设置右边距
rt.Style.GridLines.All = New prt.LineDef '将网格线类型设为默认类型
rt.Rows.Count = Tb.Rows.Count
r = Tb.Rows.Count '设置行数
'表可见列数
colscount=0
M=0
For Each cl As col In tb.cols
If cl.visible=True
colscount=colscount+1
l = cr(cl.name)
rt.Cols(M).Width = l
M=M+1
End If
Next
rt.Cols.Count =colscount '设置列数
For n As Integer = 0 To tb.rows.count(True)-1 Step 1
Dim dr As Row=tb.rows(n,True)
m=0
For Each cl As col In tb.cols
If cl.visible=True And n=0
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '文本内容水平居中
rt.Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Cells(0,m).Text =cl.name
If cl.IsNumeric
If dr.IsNull(cl.name)= False
rt.Cells(n+1,m).Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Cells(n+1,m).Style.TextAlignHorz = prt.AlignHorzEnum.right
If Isnumeric(dr(cl.name).Tostring) Then
rt.Cells(n+1,m).Text = Format(dr(cl.name),"#,##0.00")
Else
rt.Cells(n+1,m).Text = dr(cl.name).Tostring
End If
End If
End If
If cl.IsString
rt.Cells(n+1,m).Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Cells(n+1,m).Style.TextAlignHorz = prt.AlignHorzEnum.left
rt.Cells(n+1,m).Text =dr(cl.name)
End If
m=m+1
End If
If cl.visible=True And n<>0
If cl.IsNumeric
If dr.IsNull(cl.name) = False
rt.Cells(n+1,m).Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Cells(n+1,m).Style.TextAlignHorz = prt.AlignHorzEnum.right
If Isnumeric(dr(cl.name).Tostring) Then
rt.Cells(n+1,m).Text = Format(dr(cl.name),"#,##0.00")
Else
rt.Cells(n+1,m).Text = dr(cl.name).Tostring
End If
End If
End If
If cl.IsString Or cl.Isdate
rt.Cells(n+1,m).Style.TextAlignHorz = prt.AlignHorzEnum.left
rt.Cells(n+1,m).Style.TextAlignVert = prt.AlignVertEnum.Center
rt.Cells(n+1,m).Text =dr(cl.name)
End If
m=m+1
End If
Next
Next
rt.RowGroups(0, tb.HeaderRows).Header = prt.TableHeaderEnum.All '利用行组功能设置表头
tb.AutoSizeRows()
doc.Body.Children.Add(rs) '将文本对象加入到表格中
doc.Body.Children.Add(rs1) '将文本对象加入到表格中
doc.Body.Children.Add(rt) '将表格对象加入到报表中
rs = New prt.RenderText() '再次定义一个文本对象
rs1 = New prt.RenderText() '再次定义一个文本对象
doc.Body.Children.Add(rs) '将文本对象加入到表格中
doc.Body.Children.Add(rs1) '将文本对象加入到表格中
Doc.Preview() '预览报表