Foxtable(狐表)用户栏目专家坐堂 → [求助]表格转换


  共有3666人关注过本帖树形打印复制链接

主题:[求助]表格转换

帅哥哟,离线,有人找我吗?
大红袍
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/4/21 18:32:00 [显示全部帖子]

Dim dtb As New DataTableBuilder("表B")
Dim Names As New List(Of String) 

dtb.AddDef("班级",Gettype(String),10)
dtb.AddDef("姓名",Gettype(String),10)
For Each v As String In DataTables("学生成绩").GetValues("科目")
    dtb.AddDef(v, Gettype(Double))
Names.Add(v) 
Next
dtb.Build()
For Each v As String() In DataTables("学生成绩").GetValues("班级|姓名")
    Dim dr1 As DataRow = DataTables("表B").AddNew()
    dr1("班级") = v(0)
    dr1("姓名") = v(1)
    For Each dr2 As DataRow In DataTables ("学生成绩").Select("班级 = '" & v(0) & "' And 姓名 = '" & v(1) & "'")
        dr1(dr2("科目")) = dr2("分数")
    Next
Next

Dim s As String
For i As Integer = 0 To names.Count - 1
    s = s & "+isnull(" & names(i) & ",0)"
Next

DataTables("表B").DataCols.Add("总分",Gettype(Double),s.trim("+"))    ',"[语文] + [英语] + [数学] + [物理] + [化学]")
MainTable = Tables("表B")


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/4/21 20:20:00 [显示全部帖子]

Dim dtb As New DataTableBuilder("表B")
Dim Names As New List(Of String) 

dtb.AddDef("班级",Gettype(String),10)
dtb.AddDef("姓名",Gettype(String),10)
For Each v As String In DataTables("学生成绩").GetValues("科目", "科目 is not null")
    dtb.AddDef(v.Trim, Gettype(Double))
    Names.Add(v.Trim) 
Next
dtb.Build()
For Each v As String() In DataTables("学生成绩").GetValues("班级|姓名")
    Dim dr1 As DataRow = DataTables("表B").AddNew()
    dr1("班级") = v(0)
    dr1("姓名") = v(1)
    For Each dr2 As DataRow In DataTables ("学生成绩").Select("班级 = '" & v(0) & "' And 姓名 = '" & v(1) & "'")
        dr1(dr2("科目")) = dr2("分数")
    Next
Next

Dim s As String
For i As Integer = 0 To names.Count - 1
    s = s & "+isnull([" & names(i) & "],0)"
Next

DataTables("表B").DataCols.Add("总分",Gettype(Double),s.trim("+"))   
MainTable = Tables("表B")


 回到顶部