Dim Names As List(Of String) = Tables("表彰").DataTable.GetValues("登记单位")
Dim doc As New PrintDoc
Dim prs As Integer = 20 '每页20行
Dim tb As Table = Tables("表彰")
For p As Integer = 1 To math.Ceiling(tb.Rows.Count / prs) - 1
Dim rt As New prt.RenderTable
rt.Cells(0,0).Text = "黔南州检察系统表彰统计汇总表"
rt.Cells(1,0).Text = "登记单位"
rt.Cells(1,1).Text = "总数"
rt.Cells(1,2).Text = "个人表彰"
rt.Cells(1,7).Text = "集体表彰"
rt.Cells(2,0).Text = "登记单位"
rt.Cells(2,1).Text = "总数"
rt.Cells(2,2).Text = "个人表彰"
rt.Cells(2,3).Text = "国家级"
rt.Cells(2,4).Text = "省部级"
rt.Cells(2,5).Text = "地州级"
rt.Cells(2,6).Text = "县市级"
rt.Cells(2,7).Text = "集体表彰"
rt.Cells(2,8).Text = "国家级"
rt.Cells(2,9).Text = "省部级"
rt.Cells(2,10).Text = "地州级"
rt.Cells(2,11).Text = "县市级"
rt.Cells(0,0).SpanCols = 12 '第1行第1个单元格向右合并12列
rt.Cells(1,0).SpanRows = 2 '第1行第1个单元格向下合并2行
rt.Cells(1,1).SpanRows = 2 '第1行第2个单元格向下合并2行
rt.Cells(1,2).SpanCols = 5 '第1行第3个单元格向右合并3列
rt.Cells(1,7).SpanCols = 5 '第1行第7个单元格向右合并5列
rt.Cols(0).Width = 40
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '内容水平居中
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '内容垂直居中
rt.Rows(0).Style.BackColor = Color.LightGray '第一行背景颜色设为灰色.
rt.Rows(1).Style.BackColor = Color.LightGray '第一行背景颜色设为灰色.
rt.RowGroups(0,4).Header = prt.TableHeaderEnum.All '将前四行作为表头.
rt.Cols(2).Style.BackColor = Color.LightGray '第一列背景颜色设为灰色.
rt.Cols(7).Style.BackColor = Color.LightGray '第一列背景颜色设为灰色.
rt.Cols(1).Style.BackColor = Color.LightGray '第一列背景颜色设为灰色.
rt.Cols(0).Style.BackColor = Color.LightGray '第一列背景颜色设为灰色.
rt.ColGroups(0,1).Header = prt.TableHeaderEnum.All '将第一列作为表头.
rt.Rows(0).Height = 10
For i As Integer = 0 To Names.Count -1
rt.Cells(i+3,0).Text= Names(i)
rt.Cells(i+3,1).Text = Tables("表彰").DataTable.Compute("Count(获奖者)","登记单位='" & Names(i) & "'")
rt.Cells(i+3,2).Text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰' And 登记单位='" & Names(i) & "'")
rt.Cells(i+3,3).Text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰' And 获奖等级='国家级' And 登记单位='" & Names(i) & "'")
rt.Cells(i+3,4).Text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰' And 获奖等级='省部级' And 登记单位='" & Names(i) & "'")
rt.Cells(i+3,5).Text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰' And 获奖等级='地州级' And 登记单位='" & Names(i) & "'")
rt.Cells(i+3,6).Text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰' And 获奖等级='县市级' And 登记单位='" & Names(i) & "'")
rt.Cells(i+3,7).Text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰' And 登记单位='" & Names(i) & "'")
rt.Cells(i+3,8).Text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰' And 获奖等级='国家级' And 登记单位='" & Names(i) & "'")
rt.Cells(i+3,9).Text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰' And 获奖等级='省部级' And 登记单位='" & Names(i) & "'")
rt.Cells(i+3,10).Text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰' And 获奖等级='地州级' And 登记单位='" & Names(i) & "'")
rt.Cells(i+3,11).Text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰' And 获奖等级='县市级' And 登记单位='" & Names(i) & "'")
Next
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) '灰色网格线
rt.CellStyle.Spacing.All = 1 '内容距离网格线1毫米
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
rt.Rows.Count = rt.Rows.Count + 1 '增加本页小计行
rt.Rows(rt.Rows.count -1)(0).text = "本页小计"
rt.Rows(rt.Rows.count -1)(1).text = Tables("表彰").DataTable.Compute("Count(获奖者)")
rt.Rows(rt.Rows.count -1)(2).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰'")
rt.Rows(rt.Rows.count -1)(3).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰'And 获奖等级='国家级'")
rt.Rows(rt.Rows.count -1)(4).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰'And 获奖等级='省部级'")
rt.Rows(rt.Rows.count -1)(5).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰'And 获奖等级='地州级'")
rt.Rows(rt.Rows.count -1)(6).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰'And 获奖等级='县市级'")
rt.Rows(rt.Rows.count -1)(7).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰'")
rt.Rows(rt.Rows.count -1)(8).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰'And 获奖等级='国家级'")
rt.Rows(rt.Rows.count -1)(9).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰'And 获奖等级='省部级'")
rt.Rows(rt.Rows.count -1)(10).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰'And 获奖等级='地州级'")
rt.Rows(rt.Rows.count -1)(11).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰'And 获奖等级='县市级'")
If p = math.Ceiling(tb.Rows.Count / prs) - 1 '如果是最后一页
rt.Rows.Count = rt.Rows.Count + 1 '增加总计行
rt.Rows(rt.Rows.count -1)(0).text = "总计"
rt.Rows(rt.Rows.count -1)(1).text = Tables("表彰").DataTable.Compute("Count(获奖者)")
rt.Rows(rt.Rows.count -1)(2).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰'")
rt.Rows(rt.Rows.count -1)(3).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰'And 获奖等级='国家级'")
rt.Rows(rt.Rows.count -1)(4).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰'And 获奖等级='省部级'")
rt.Rows(rt.Rows.count -1)(5).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰'And 获奖等级='地州级'")
rt.Rows(rt.Rows.count -1)(6).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='个人表彰'And 获奖等级='县市级'")
rt.Rows(rt.Rows.count -1)(7).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰'")
rt.Rows(rt.Rows.count -1)(8).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰'And 获奖等级='国家级'")
rt.Rows(rt.Rows.count -1)(9).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰'And 获奖等级='省部级'")
rt.Rows(rt.Rows.count -1)(10).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰'And 获奖等级='地州级'")
rt.Rows(rt.Rows.count -1)(11).text = Tables("表彰").DataTable.Compute("Count(获奖者)","表彰类别='集体表彰'And 获奖等级='县市级'")
Else
rt.BreakAfter = prt.BreakEnum.Page '否则换页
End If
doc.Body.Children.Add(rt)
Next
doc.Preview()