Specifies the rule for determining the height of an object.
Namespace: SautinSoft.DocumentAssembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.12.16
Syntax Public Enumeration HeightRule
Members Member name | Value | Description |
---|
Auto | 0 |
The height will grow automatically to accommodate all text inside an object.
|
AtLeast | 1 |
The height will be at least the specified height in points. It will grow,
if needed, to accommodate all text inside an object.
|
Exact | 2 |
The height is specified exactly in points. Please note that if the text cannot fit
inside the object of this height, it will appear truncated.
|
Example See Developer Guide: Shows how to set a height for a table row
Shows how to set a height for a table row using C#
using SautinSoft.Document;
using SautinSoft.Document.Drawing;
using SautinSoft.Document.Tables;
using System.Linq;
namespace Example
{
class Program
{
static void Main(string[] args)
{
TableRowFormatting();
}
static void TableRowFormatting()
{
string docxPath = @"FormattedTable.docx";
DocumentCore dc = new DocumentCore();
Section s = new Section(dc);
dc.Sections.Add(s);
int rows = 30;
int columns = 5;
Table t = new Table(dc, rows, columns);
t.TableFormat.PreferredWidth = new TableWidth(100, TableWidthUnit.Percentage);
t.TableFormat.Borders.SetBorders(MultipleBorderTypes.All, BorderStyle.Single, Color.DarkGray, 1);
t.TableFormat.AutomaticallyResizeToFitContents = false;
s.Blocks.Add(t);
double oddHeight = LengthUnitConverter.Convert(10, LengthUnit.Millimeter, LengthUnit.Point);
double evenHeight = LengthUnitConverter.Convert(15, LengthUnit.Millimeter, LengthUnit.Point);
for (int r = 0; r < t.Rows.Count; r++)
{
TableRow row = t.Rows[r];
if (r % 2 != 0)
row.RowFormat.Height = new TableRowHeight(evenHeight, HeightRule.AtLeast);
else
row.RowFormat.Height = new TableRowHeight(oddHeight, HeightRule.AtLeast);
}
TableRow firstRow = t.Rows[0];
firstRow.RowFormat.RepeatOnEachPage = true;
int colSpan = firstRow.Cells.Count;
for (int c = firstRow.Cells.Count - 1; c>=1; c--)
{
firstRow.Cells.RemoveAt(c);
}
firstRow.Cells[0].ColumnSpan = colSpan;
Paragraph p = new Paragraph(dc);
p.Inlines.Add(new Run(dc, "This is the Row 0 (RepeatOnEachPage = true)", new CharacterFormat() { FontColor = Color.Blue, Size = 20 }));
p.ParagraphFormat.Alignment = HorizontalAlignment.Center;
t.Rows[0].Cells[0].Blocks.Add(p);
TableRow rowTotal = new TableRow(dc);
rowTotal.Cells.Add(new TableCell(dc));
rowTotal.Cells[0].Content.Start.Insert(string.Format("Total rows: {0}", rows), new CharacterFormat() { FontColor = Color.Red, Size = 30 });
rowTotal.RowFormat.GridBefore = columns-1;
rowTotal.RowFormat.Height = new TableRowHeight(evenHeight, HeightRule.AtLeast);
t.Rows.Add(rowTotal);
dc.Save(docxPath);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(docxPath) { UseShellExecute = true });
}
}
}
Shows how to set a height for a table row using VB.Net
Imports SautinSoft.Document
Imports SautinSoft.Document.Drawing
Imports SautinSoft.Document.Tables
Imports System.Linq
Namespace Example
Friend Class Program
Shared Sub Main(ByVal args() As String)
TableRowFormatting()
End Sub
Private Shared Sub TableRowFormatting()
Dim docxPath As String = "FormattedTable.docx"
Dim dc As New DocumentCore()
Dim s As New Section(dc)
dc.Sections.Add(s)
Dim rows As Integer = 30
Dim columns As Integer = 5
Dim t As New Table(dc, rows, columns)
t.TableFormat.PreferredWidth = New TableWidth(100, TableWidthUnit.Percentage)
t.TableFormat.Borders.SetBorders(MultipleBorderTypes.All, BorderStyle.Single, Color.DarkGray, 1)
t.TableFormat.AutomaticallyResizeToFitContents = False
s.Blocks.Add(t)
Dim oddHeight As Double = LengthUnitConverter.Convert(10, LengthUnit.Millimeter, LengthUnit.Point)
Dim evenHeight As Double = LengthUnitConverter.Convert(15, LengthUnit.Millimeter, LengthUnit.Point)
For r As Integer = 0 To t.Rows.Count - 1
Dim row As TableRow = t.Rows(r)
If r Mod 2 <> 0 Then
row.RowFormat.Height = New TableRowHeight(evenHeight, HeightRule.AtLeast)
Else
row.RowFormat.Height = New TableRowHeight(oddHeight, HeightRule.AtLeast)
End If
Next r
Dim firstRow As TableRow = t.Rows(0)
firstRow.RowFormat.RepeatOnEachPage = True
Dim colSpan As Integer = firstRow.Cells.Count
For c As Integer = firstRow.Cells.Count - 1 To 1 Step -1
firstRow.Cells.RemoveAt(c)
Next c
firstRow.Cells(0).ColumnSpan = colSpan
Dim p As New Paragraph(dc)
p.Inlines.Add(New Run(dc, "This is the Row 0 (RepeatOnEachPage = true)", New CharacterFormat() With {
.FontColor = Color.Blue,
.Size = 20
}))
p.ParagraphFormat.Alignment = HorizontalAlignment.Center
t.Rows(0).Cells(0).Blocks.Add(p)
Dim rowTotal As New TableRow(dc)
rowTotal.Cells.Add(New TableCell(dc))
rowTotal.Cells(0).Content.Start.Insert(String.Format("Total rows: {0}", rows), New CharacterFormat() With {
.FontColor = Color.Red,
.Size = 30
})
rowTotal.RowFormat.GridBefore = columns-1
rowTotal.RowFormat.Height = New TableRowHeight(evenHeight, HeightRule.AtLeast)
t.Rows.Add(rowTotal)
dc.Save(docxPath)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(docxPath) With {.UseShellExecute = True})
End Sub
End Class
End Namespace
See Also