再谈合并单元格
在命令窗口执行下面的代码:
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()
在换页的位置会出现下图所示的情况:
- RenderTable有一个属性RepeatGridLinesVert,这是一个逻辑属性,用于设置单元格因为
垂直换页被分割为多个单元格时,是否重复打印水平表格线。
- 单元格有一个属性VertSplitBehavior属性,该属性是CellSplitBehaviorEnum性枚举,用于设置单元格因为
垂直换页被分割为多个单元格时,如何打印单元格内容。
此枚举有三个可选值:
Cut: 只打印一次
Copy: 每次换页都打印
Split:内容很长的时候,自动延伸到下一页。
综上所述,我们应该将代码改为:
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