以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  求改代码 多个列自动取值并进行统计  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=84465)

--  作者:huozhe
--  发布时间:2016/5/3 11:25:00
--  求改代码 多个列自动取值并进行统计
Dim st As Date = Date.Now
Dim lts As List(Of String)
Dim lts1 As List(Of String)
lts = DataTables("采集表").GetUniqueValues("", "民族")
lts1 = DataTables("采集表").GetUniqueValues("", "性别")
Dim b As New SQLGroupTableBuilder("综合统计","采集表")
b.Groups.Adddef("类别")
b.filter="类别 is not null"
b.Totals.Adddef("类别",AggregateEnum.Count,"小计")
For i As Integer = 0 To lts.count -1
b.Totals.Addexp("民族_"& lts(i),"IIF(民族 = \'lts(i)\',1,0)")
Next
For i As Integer = 0 To lts1.count -1
b.Totals.Addexp("性别_"& lts1(i),"IIF(性别 = \'lts1(i)\',1,0)")
Next
b.VerticalTotal = True
b.Build 
With Tables("综合统计")
.DefaultColWidth = 40
.DefaultRowHeight = 40
.Cols(0).Width = 120
.AllowDragColumn = False
.AllowResizeRow = False
.SetHeaderRowHeight(40,100)
.AllowResizeColumn = False
.AllowEdit = False
.Grid.Styles.Normal.Border.Color = Color.black
End With
DataTables("综合统计").SysStyles("Alternate").BackColor = Color.LightYellow
MainTable = Tables("综合统计")
StatusBar.Message3 = "耗时: " & (Date.Now - st).TotalSeconds & "秒"


--  作者:大红袍
--  发布时间:2016/5/3 11:33:00
--  
For i As Integer = 0 To lts.count -1
b.Totals.Addexp("民族_"& lts(i),"IIF(民族 = \'" & lts(i) & "\',1,0)")
Next
For i As Integer = 0 To lts1.count -1
b.Totals.Addexp("性别_"& lts1(i),"IIF(性别 = \'" & lts1(i) & "\',1,0)")
Next

--  作者:大红袍
--  发布时间:2016/5/3 11:34:00
--  

贴代码的同时,最好有具体实例可以测试。