在你原来代码上改了些内容,虽方法不太好,勉强用一下吧。最好是把你的项目放上来。
Dim dt As DataTable
Dim g As New GroupTableBuilder("统计表1", DataTables("fenfa"))
g.Groups.AddDef("faby","投递员")
g.Groups.AddDef("baom","报刊名称")
g.Totals.AddDef("fens","份数")
g.Filter = "[zzrq] >= '1/1/2012 ' And [zzrq] <= '12/31/2012 ' And [pian] = '城西 '"
g.FromServer = True
dt = g.Build(True)
Dim doc As New PrintDoc
Dim rt As New prt.RenderTable
Dim Count As Integer = 1Dim cur_name As String = ""rt.Cells(0, 0) = "投递员"rt.Cells(0, 1) = "日报"rt.Cells(0, 2) = "晚报"For Each r As DataRow In dt.DataRows If r("投递员") <> cur_name Then '不是同一个投递员 rt.Cells(count, 0).Text = r("投递员") rt.Cells(count, 1).Text = r("份数") '日报 cur_name = r("投递员") Else rt.Cells(count, 2).Text = r("份数") '晚报 count = count + 1 '完结 End IfNext'Dim Count As Integer = 0
'For Each Col As DataCol In Dt.DataCols
'rt.Cells(0,Count).Text = Col.Name
'For r As Integer = 0 To dt.DataRows.Count - 1
'rt.Cells(r +1,Count).Text = dt.DataRows(r)(Col.Name)
'Next
'Count = Count + 1
'Next
rt.Style.Gridlines.All = New prt.Linedef(Color.Gray)
rt.CellStyle.Spacing.All = 1
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center
rt.Style.Font = New Font("宋体", 20, FontStyle.Bold) '设置字体
rt.Style.GridLines.All = New prt.LineDef '将网格线类型设为默认类型
rt.Height = 710 '设置表格的高度为120毫米
'去除了合并的单元格
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '垂直居中
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '第一行内容水平居中
rt.Rows(0).Style.TextAlignVert = prt.AlignVertEnum.Center '第一行内容垂直居中
rt.Rows(0).Style.BackColor = Color.LightGray '第一行背景颜色设为灰色.
rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All '将第一行作为表头.
doc.Body.Children.Add(rt)
doc.Preview()
[此贴子已经被作者于2012-9-5 14:02:21编辑过]