-- 作者:yyzlxc
-- 发布时间:2011/9/1 20:23:00
-- [求助]代码修改(已解决)
根据《报表源表》,利用交叉统计代码生成《当月日汇总》表,存在两个问题:
1、按日期垂直分组,由于列标题没有显示月份,所以将7月份的数据排在后面,而将8月1日的数据列在最前面,有没有办法,能将月份也与日期同时显示。
2、每个分组的全员人数是整数,没有必要显示两位小数,如何像“单位”和“名次”一样不进行格式化。
附上项目文件,请各位老师帮助指教,谢谢!!
以下是按钮代码:
Dim s As String Dim b As New CrossTableBuilder("当月日汇总", DataTables("报表源表")) b.HGroups.AddDef("单位") b.VGroups.AddDef("日期",DateGroupEnum.Day,"{0}日") b.Totals.AddDef("加工费") b.Totals.AddDef("投工","全员人数") b.Totals.AddDef("人均","人均加工费") b.HorizontalTotal = True b.VerticalTotal = True b.Build() MainTable = Tables("当月日汇总") \'打开生成的统计表 Dim t As Table = Tables("当月日汇总") Dim i As Integer =(Tables("当月日汇总").Cols.Count-4)/3 For Each r As Row In t.Rows For j As Byte = 1 To i If r("投工_" & j) <> 0 Then r("人均_" & j) = r("加工费_" & j)/r("投工_" & j) End If Next Next t.DataTable.DataCols.Add("合计_月均人数", Gettype(Double),"[合计_投工]/" & i) t.DataTable.DataCols.Add("月人均加工费", Gettype(Double),"合计_加工费/合计_月均人数") t.DataTable.DataCols.Add("名次", Gettype(Byte)) t.Cols.Remove("合计_投工","合计_人均") Dim drs As List(Of DataRow) = t.DataTable.Select("[单位] <> \'合计\'","月人均加工费 DESC") For n As Byte = 0 To drs.Count - 1 \'遍历所有行 If n > 0 AndAlso drs(n)("月人均加工费") = drs(n-1)("月人均加工费") Then \'如果月人均加工费和上一行相同 drs(n)("名次") = drs(n-1)("名次") \'则排名等于上一行 Else drs(n)("名次") = n + 1 \'设置名次 End If Next For Each dc As DataCol In t.DataTable.DataCols If dc.name <> "单位" AndAlso dc.name <> "名次" Then s="0.00" t.DataTable.DataCols(dc.Name).SetFormat(s) End If Next t.Cols("单位").TextAlign = TextAlignEnum.Center t.Cols("名次").TextAlign = TextAlignEnum.Center t.AutoSizeCols() MainTable =t Tables("当月日汇总").Cols.Frozen = 1 \'冻结一列
[此贴子已经被作者于2011-9-2 14:56:04编辑过]
|
-- 作者:狐狸爸爸
-- 发布时间:2011/9/2 8:51:00
--
Dim s As String Dim b As New CrossTableBuilder("当月日汇总", DataTables("报表源表")) b.HGroups.AddDef("单位") b.VGroups.AddDef("日期",DateGroupEnum.Month,"{0}月") b.VGroups.AddDef("日期",DateGroupEnum.Day,"{0}日") b.Totals.AddDef("加工费") b.Totals.AddDef("投工","全员人数") b.Totals.AddDef("人均","人均加工费") b.HorizontalTotal = True b.VerticalTotal = True b.Build() MainTable = Tables("当月日汇总") \'打开生成的统计表 Dim t As Table = Tables("当月日汇总") Dim i As Integer =(Tables("当月日汇总").Cols.Count-4)/3 For Each r As Row In t.Rows For j As Byte = 1 To i If r("投工_" & j) <> 0 Then r("人均_" & j) = r("加工费_" & j)/r("投工_" & j) End If Next Next t.DataTable.DataCols.Add("合计_月均人数", Gettype(Double),"[合计_投工]/" & i) t.DataTable.DataCols.Add("月人均加工费", Gettype(Double),"合计_加工费/合计_月均人数") t.DataTable.DataCols.Add("名次", Gettype(Byte)) t.Cols.Remove("合计_投工","合计_人均") Dim drs As List(Of DataRow) = t.DataTable.Select("[单位] <> \'合计\'","月人均加工费 DESC") For n As Byte = 0 To drs.Count - 1 \'遍历所有行 If n > 0 AndAlso drs(n)("月人均加工费") = drs(n-1)("月人均加工费") Then \'如果月人均加工费和上一行相同 drs(n)("名次") = drs(n-1)("名次") \'则排名等于上一行 Else drs(n)("名次") = n + 1 \'设置名次 End If Next For Each dc As DataCol In t.DataTable.DataCols If dc.name <> "单位" AndAlso dc.name <> "名次" Then s="0.00" t.DataTable.DataCols(dc.Name).SetFormat(s) End If Next t.Cols("单位").TextAlign = TextAlignEnum.Center t.Cols("名次").TextAlign = TextAlignEnum.Center t.AutoSizeCols() MainTable =t For Each dc As DataCol In DataTables("当月日汇总").dataCols If dc.name.StartsWith("投工_") Then dc.SetFormat("####0") End If Next Tables("当月日汇总").Cols.Frozen = 1 \'冻结一列
|