以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  请问怎么改呀代码  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=23191)

--  作者:周子杰
--  发布时间:2012/9/5 10:29:00
--  请问怎么改呀代码

 
图片点击可在新窗口打开查看此主题相关图片如下:4.jpg
图片点击可在新窗口打开查看
 

 

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 = 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.Cells(1,0).SpanRows = 2
rt.Cells(3,0).SpanRows = 2
rt.Cells(5,0).SpanRows = 2
rt.Cells(7,0).SpanRows = 2
rt.Cells(9,0).SpanRows = 2
rt.Cells(11,0).SpanRows = 2
rt.Cells(13,0).SpanRows = 2
rt.Cells(15,0).SpanRows = 2
rt.Cells(17,0).SpanRows = 2
rt.Cells(19,0).SpanRows = 2
rt.Cells(21,0).SpanRows = 2
rt.Cells(23,0).SpanRows = 2
rt.Cells(25,0).SpanRows = 2
rt.Cells(27,0).SpanRows = 2
rt.Cells(29,0).SpanRows = 2
rt.Cells(31,0).SpanRows = 2
rt.Cells(33,0).SpanRows = 2
rt.Cells(35,0).SpanRows = 2
rt.Cells(37,0).SpanRows = 2
rt.Cells(39,0).SpanRows = 2
rt.Cells(41,0).SpanRows = 2
rt.Cells(43,0).SpanRows = 2
rt.Cells(45,0).SpanRows = 2
rt.Cells(47,0).SpanRows = 2
rt.Cells(49,0).SpanRows = 2
rt.Cells(51,0).SpanRows = 2
rt.Cells(53,0).SpanRows = 2
rt.Cells(55,0).SpanRows = 2
rt.Cells(57,0).SpanRows = 2
rt.Cells(59,0).SpanRows = 2
rt.Cells(61,0).SpanRows = 2
rt.Cells(63,0).SpanRows = 2
rt.Cells(65,0).SpanRows = 2
rt.Cells(67,0).SpanRows = 2
rt.Cells(69,0).SpanRows = 2
rt.Cells(71,0).SpanRows = 2
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()

原代码如上。

 但是打印出来太多页数了,我想变成如下效果的统计,请问高手,如何写代码呀

 

  投递员    日报   晚报      
   曹晓玲    233    447    

--  作者:狐狸爸爸
--  发布时间:2012/9/5 11:03:00
--  
这种打印,你就用excel报表吧
--  作者:lin_hailun
--  发布时间:2012/9/5 13:58:00
--  
在你原来代码上改了些内容,虽方法不太好,勉强用一下吧。最好是把你的项目放上来。

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 = 1
Dim 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 If
Next

\'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编辑过]