Dim i,i1,i2,i3,i4 as Integer
Dim Ta,Ta1 As Table
Ta = Tables("学生各学科前5名成绩单")
Ta1 = Tables("学生各科成绩表")
Dim Ls As String() = {"数学","英语","政治","历史","地理","生物","物理"}
datatables("学生各学科前5名成绩单").datarows.clear()
dim f As New Filler
f.SourceTable = DataTables("学生各科成绩表")
f.SourceCols = "班级,年级,语文班级排名,姓名,语文"
f.DataTable = DataTables("学生各学科前5名成绩单")
f.DataCols = "班级,年级,语文_名次,语文_姓名,语文_成绩"
f.Filter="[语文班级排名]<=5"
f.Fill() '填充
Ta.Sort = "年级,班级"
For i1 = 0 To Ls.Length-1
Ta1.Filter = "[" & Ls(i1) & "班级排名] <=5"
i = Ta.Rows.count-1
i2 = Ta1.Rows.count-1
If i < i2 Then
Ta.Addnew(i2-i1)
End if
i3 = Math.Max(i1,i2)
For i4 = 0 to i3
Ta.Rows(i4)(Ls(i1) & "_名次") = Ta1.Rows(i4)(Ls(i1) & "班级排名")
Ta.Rows(i4)(Ls(i1) & "_姓名") = Ta1.Rows(i4)("姓名")
Ta.Rows(i4)(Ls(i1) & "_成绩") = Ta1.Rows(i4)(Ls(i1))
Next
Next
Dim Ft As String
For Each dc As DataCol In DataTables("学生各学科前5名成绩单").DataCols
Ft = Ft & " and " & dc.Name & " Is Null"
Next
DataTables("学生各学科前5名成绩单").DeleteFor(Ft.SubString(5))