以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]水平表和垂直表转换  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=158056)

--  作者:lgj716330
--  发布时间:2020/11/6 10:51:00
--  [求助]水平表和垂直表转换

此主题相关图片如下:2233.png
按此在新窗口浏览图片

要把上表转换成下表要怎么弄
Dim dtb As New DataTableBuilder("B")
dtb.AddDef(
"姓名", Gettype(String), 32)
For Each
v As String In DataTables("A").GetValues("课程")
   
dtb.AddDef(v, Gettype(Double))
Next

dtb.Build()

For Each
v As String In DataTables("A").GetValues("姓名")
   
Dim dr1 As DataRow = DataTables("B").AddNew()
    dr1(
"姓名") = v
   
For Each dr2 As DataRow In DataTables("A").Select("姓名 = \'" & v & "\'")
       dr1(dr2("课程")) = dr2("分数")
   
Next
Next
MainTable = Tables(
"表B")

--  作者:有点蓝
--  发布时间:2020/11/6 11:11:00
--  
Dim dtb As New DataTableBuilder("表B")
dtb.AddDef("学期", Gettype(String), 32)
dtb.AddDef("科目", Gettype(String), 32)
For Each v As String In DataTables("表A").GetValues("姓名")
    dtb.AddDef(v, Gettype(Double))
Next
dtb.Build()
For Each v As String In DataTables("表A").GetValues("学期")
    For Each dc As DataCol In DataTables("表A").datacols
        If dc.name <> "学期" AndAlso dc.name <> "姓名"
            Dim dr1 As DataRow = DataTables("表B").AddNew()
            dr1("学期") = v
            dr1("科目") = dc.name
            For Each v2() As String In DataTables("表A").GetValues("姓名|" & dc.name)
                dr1(v2(0)) = v2(1)
            Next
        End If
    Next
Next
MainTable = Tables("表B")

--  作者:lgj716330
--  发布时间:2020/11/6 13:46:00
--  
表A是个统计表,有个分组统计生成的汇总行,For Each v As String In DataTables("表A").GetValues("姓名"),如何把汇总行取过来呢
--  作者:有点蓝
--  发布时间:2020/11/6 13:48:00
--  
请截图说明
--  作者:lgj716330
--  发布时间:2020/11/6 14:25:00
--  
Dim t1 As Table = Tables("表A")
Dim g As Subtotalgroup  
t1.SubtotalGroups.Clear()
t1.GroupAboveData = False
t1.TreeVisible = False
t1.SpillNode = False

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Average
g.GroupOn = "*"
g.TotalOn = cs.trim(",")
g.Caption = "平均"
t1.SubtotalGroups.Add(g)
t1.Subtotal()


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


--  作者:有点蓝
--  发布时间:2020/11/6 14:36:00
--  
Dim dtb As New DataTableBuilder("表B")
dtb.AddDef("学期", Gettype(String), 32)
dtb.AddDef("科目", Gettype(String), 32)
For Each v As String In DataTables("表A").GetValues("姓名")
    dtb.AddDef(v, Gettype(Double))
Next
dtb.AddDef("平均", Gettype(Double))
dtb.Build()
For Each v As String In DataTables("表A").GetValues("学期")
    For Each dc As DataCol In DataTables("表A").datacols
        If dc.name <> "学期" AndAlso dc.name <> "姓名"
            Dim dr1 As DataRow = DataTables("表B").AddNew()
            dr1("学期") = v
            dr1("科目") = dc.name
dim sum as double = 0
Dim Arys As List(Of String()) = DataTables("表A").GetValues("姓名|" & dc.name)
            For Each v2() As String In Arys
                dr1(v2(0)) = v2(1)
sum+=val(v2(1))
            Next
dr1("平均") = sum / Arys.count
        End If
    Next
Next
MainTable = Tables("表B")

--  作者:lgj716330
--  发布时间:2020/11/6 17:02:00
--  
Dim t1 As Table = Tables("统计表") 
Dim i As Integer = t1.Rows.Count(True) - 1
Dim m1 As Double = Tables("统计表")(i,"数量")


提示错误:未将对象引用设置到对象的实例。

--  作者:有点蓝
--  发布时间:2020/11/6 17:15:00
--  
Dim m1 As Double = Tables("统计表").rows(i,true)("数量")