使用C1PrintDocument控件 > 表格 > 表格以及列宽,行高 |
C1PrintDocument表格中的行和列均可以为自动计算尺寸,但是行和列的默认行为有所不同。默认情况下,行的高度为自动计算(按照该行单元格的内容进行计算),而列的宽度为固定值。RenderTable的默认宽度下面的代码将创建一个页面等宽的表格,具有三个宽度相等的列,以及10行按照单元格的内容自动计算高度的行:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Dim rt As New C1.C1Preview.RenderTable() rt.Style.GridLines.All = LineDef.Default Dim row As Integer = 0 Do While (row < 10) Dim col As Integer = 0 Do While (col < 3) rt.Cells(row, col).Text = String.Format( _ "Cell({0},{1})", row, col) col += 1 Loop row += 1 Loop doc.Body.Children.Add(rt) |
C#
C# |
拷贝代码
|
---|---|
RenderTable rt = new RenderTable(); rt.Style.GridLines.All = LineDef.Default; for (int row = 0; row < 10; ++row) for (int col = 0; col < 3; ++col) rt.Cells[row, col].Text = string.Format( "Cell({0}, {1})", row, col); doc.Body.Children.Add(rt); |
使用一个全部自动计算尺寸的表格,相比默认设置,必须完成以下两件事情:
这是修改后的代码:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Dim rt As New C1.C1Preview.RenderTable() rt.Style.GridLines.All = LineDef.Default Dim row As Integer = 0 Do While (row < 10) Dim col As Integer = 0 Do While (col < 3) rt.Cells(row, col).Text = String.Format( _ "Cell({0},{1})", row, col) col += 1 Loop row += 1 Loop rt.Width = Unit.Auto rt.ColumnSizingMode = TableSizingModeEnum.Auto doc.Body.Children.Add(rt) |
C#
C# |
拷贝代码
|
---|---|
RenderTable rt = new RenderTable(); rt.Style.GridLines.All = LineDef.Default; for (int row = 0; row < 10; ++row) for (int col = 0; col < 3; ++col) rt.Cells[row, col].Text = string.Format( "Cell({0}, {1})", row, col); rt.Width = Unit.Auto; rt.ColumnSizingMode = TableSizingModeEnum.Auto; doc.Body.Children.Add(rt); |
修改后的代码使得表格中的每一列的宽度适显示应该列中单元格全部文本的宽度。