再谈合并单元格

在命令窗口执行下面的代码:

Dim doc As New PrintDoc
Dim
rt As New prt.RenderTable()
doc
.Body.Children.Add(rt)
rt.Style.GridLines.All = New prt.Linedef

For
r As integer = 0 to 100
    If
r Mod 6 = 0 Then
        rt
.Cells(r,0).Text = r & "-" & (r + 5)
        rt
.Cells(r,0).SpanRows = 6
    End If
    For
c As integer = 1 to 10
        rt.Cells(r, c).Text = r & "," & c
    Next
Next

doc
.Preview
()

在换页的位置会出现下图所示的情况:

 

综上所述,我们应该将代码改为:

Dim doc As New PrintDoc
Dim
rt As New prt.RenderTable()
doc
.Body.Children.Add(rt)
rt.Style.GridLines.All = New prt.Linedef
rt
.RepeatGridLinesVert = True
For
r As integer = 0 to 100
    If
r Mod 6 = 0 Then
        rt
.Cells(r,0).Text = r & "-" & (r + 5)
        rt
.Cells(r,0).SpanRows = 6
       
rt.Cells(r,0).VertSplitBehavior = prt.CellSplitBehaviorEnum.Copy
    End If
    For
c As integer = 1 to 10
        rt.Cells(r, c).Text = r & "," & c
    Next
Next

doc
.Preview()

注意加粗的两行代码。

打印效果:


本页地址:http://www.foxtable.com/webhelp/topics/2050.htm