以下是引用xxfoxtable在2018/10/18 20:23:00的发言:姓名行数不固定啊,怎么写代码?
[此贴子已经被作者于2018/10/18 20:23:59编辑过]
Dim t As Table = Tables("表a")
'取消合并
Dim ls As new List(of object)
For Each r As object In t.Grid.MergedRanges
ls.add(r)
Next
For Each r As object In ls
t.Grid.MergedRanges.Remove(r)
Next
'设置合并
Dim i As Integer = t.Cols("第一列").Index
Dim ii As Integer = t.Cols("第二列").Index
Dim top As Integer = 0
For j As Integer = 1 To t.Rows.count-1
Dim r1 As Row = t.Rows(j-1)
Dim r2 As Row = t.Rows(j)
Dim same As Boolean = True
If r2(i) = Nothing OrElse r1(i) <> r2(i) Then
same = False
End If
If same = False Then
t.Grid.AllowMerging = C1.Win.C1FlexGrid.AllowMergingEnum.Custom
Dim rng As C1.Win.C1FlexGrid.CellRange = t.Grid.GetCellRange(top+t.HeaderRows, ii+1, j+t.HeaderRows-1, ii+1)
t.Grid.MergedRanges.add(rng)
Top = j
ElseIf j = t.rows.count-1 Then
Dim rng As C1.Win.C1FlexGrid.CellRange = t.Grid.GetCellRange(top+t.HeaderRows, ii+1, j+t.HeaderRows, ii+1)
t.Grid.MergedRanges.add(rng)
End If
Next