Dim dws() As String = {"梁平中学","红旗中学","梁平一中","实中双桂","屏锦中学","袁驿中学","福禄中学"}
Dim a1s() As String = {"经办人","联系电话","分管领导","分管领导电话"}
Dim jb As New SQLJoinTableBuilder("查询表1","成绩库")
jb.AddCols("年级","学科","Cstr(大袋40份) as " & dws(0) & "_大袋40份","大袋30份 as " & dws(0) & "_大袋30份","小袋5份 as " & dws(0) & "_小袋5份","[大袋40份] * 40 + [大袋30份] * 30 + [小袋5份] * 5 as " & dws(0) & "_合计")
jb.Filter = "年级='2018' and 单位='" & dws(0) & "'"
Dim d As fxDataSource = jb.BuildDataSource()
For i As Integer = 1 To dws.Length - 1
Dim jb1 As New SQLJoinTableBuilder("查询表1","成绩库")
jb1.AddCols("年级","学科","Cstr(大袋40份) as " & dws(i) & "_大袋40份","大袋30份 as " & dws(i) & "_大袋30份","小袋5份 as " & dws(i) & "_小袋5份","[大袋40份] * 40 + [大袋30份] * 30 + [小袋5份] * 5 as " & dws(i) & "_合计")
jb1.Filter = "年级='2018' and 单位='" & dws(i) & "'"
Dim d1 As fxDataSource = jb1.BuildDataSource()
Dim Cols As String = "年级|学科"
d.Combine(Cols.split("|"),d1,Cols.split("|"))
Next
d.Show("查询表1")
Tables("查询表1").AutoSizeCols
MainTable = Tables("查询表1")
For Each a1 As String In a1s
Dim dr2 As DataRow = DataTables("成绩库").Find("单位 = '梁平中学' And 年级 = '2018' ")
Dim dr3 As DataRow = DataTables("成绩库").Find("单位 = '红旗中学' And 年级 = '2018' ")
Dim dr4 As DataRow = DataTables("成绩库").Find("单位 = '梁平一中' And 年级 = '2018' ")
Dim dr5 As DataRow = DataTables("成绩库").Find("单位 = '实中双桂' And 年级 = '2018' ")
Dim dr6 As DataRow = DataTables("成绩库").Find("单位 = '屏锦中学' And 年级 = '2018' ")
Dim dr7 As DataRow = DataTables("成绩库").Find("单位 = '袁驿中学' And 年级 = '2018' ")
Dim dr8 As DataRow = DataTables("成绩库").Find("单位 = '福禄中学' And 年级 = '2018' ")
Dim a2 As String = dr2(""& a1 &"")
Dim a3 As String = dr3(""& a1 &"")
Dim a4 As String = dr4(""& a1 &"")
Dim a5 As String = dr5(""& a1 &"")
Dim a6 As String = dr6(""& a1 &"")
Dim a7 As String = dr7(""& a1 &"")
Dim a8 As String = dr8(""& a1 &"")
Dim s() As Integer = {0,2,6,10,14,18,22,26}
Dim a() As String = {""& a1 &"","" & a2 & "","" & a3 & "","" & a4 & "","" & a5 & "","" & a6 & "","" & a7 & "","" & a8 & ""}
Dim r As Row = Tables("查询表1").AddNew
For i As Integer = 0 To s.length - 1
Tables("查询表1").Cols(s(i)).TextAlign = TextAlignEnum.Center
r(Tables("查询表1").Cols(s(i)).Name) = a(i)
Next
Dim ii As Integer = Tables("查询表1").Rows.Count + 1
Dim tb As Table = Tables("查询表1")
tb.Grid.AllowMerging = C1.Win.C1FlexGrid.AllowMergingEnum.Custom
Dim rng As C1.Win.C1FlexGrid.CellRange = tb.Grid.GetCellRange(ii, 1, ii, 2)
tb.Grid.MergedRanges.Add(rng)
For Each i As Integer In s
If i <> 0
rng = tb.Grid.GetCellRange(ii, i+1, ii, i+4)
tb.Grid.MergedRanges.Add(rng)
End If
Next
Next
执行结果:

此主题相关图片如下:汇总统计结果4.png

此代码已经解决上面的问题了,但代码有点复杂。如何简化代码中的红色部分?请指教,谢谢!