Dim bu As new StringBuilder
Dim idx As Integer = 1
Dim s As String = ""
For Each nj As String In DataTables("报名表").GetValues("班级", "班级 is not null", "班级")
nj = nj.Substring(0,1)
If nj <> s Then
s = nj
For Each c As Col In Tables("报名表").Cols
If c.Name.Contains("男") OrElse c.Name.Contains("女")
Dim drs As List(of DataRow) = DataTables("报名表").Select("班级 like '%" & s & "年级%' and " & c.Name & " = '√'", "班级")
If drs.Count = 0 Then Continue For
Dim ls1 As new List(of String)
Dim ls2 As new List(of String)
Dim ls3 As new List(of String)
For i As Integer = 0 To drs.count-1 Step 3
ls1.add(drs(i)("号码"))
If i+1 < drs.count Then ls2.add(drs(i+1)("号码"))
If i+2 < drs.count Then ls3.add(drs(i+2)("号码"))
Next
Dim arr() As String = c.Name.Split("_")
If arr.Length = 2 Then
bu.AppendLine(s & "年级" & arr(1) & "子" & arr(0) & "预赛(共三组)")
Else
bu.AppendLine(s & "年级" & c.Name & "预赛(共三组)")
End If
bu.AppendLine("第一组:" & String.Join(" ",ls1.ToArray))
bu.AppendLine("第二组:" & String.Join(" ",ls2.ToArray))
bu.AppendLine("第三组:" & String.Join(" ",ls3.ToArray))
End If
Next
End If
Next
Output.Show(bu.ToString)
Dim tm As String = ProjectPath & "Attachments\0101.docx" '指定模板文件
Dim fl As String = ProjectPath & "Reports\_0101.docx" '指定目标文件
Dim wrt As New WordReport(Tables("报名表"),tm,fl) '定义一个WordReport
wrt.ReplaceOne("[班级]",bu.ToString)
wrt.BuildOne(Tables("报名表").Current)
wrt.Show() '显示报表