height_rule property

RowFormat.height_rule property

Gets or sets the rule for determining the height of the table row.

@property
def height_rule(self) -> aspose.words.HeightRule:
    ...

@height_rule.setter
def height_rule(self, value: aspose.words.HeightRule):
    ...

Examples

Shows how to create a formatted table using DocumentBuilder.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

table = builder.start_table()
builder.insert_cell()
table.left_indent = 20

# Set some formatting options for text and table appearance.
builder.row_format.height = 40
builder.row_format.height_rule = aw.HeightRule.AT_LEAST
builder.cell_format.shading.background_pattern_color = drawing.Color.from_argb(198, 217, 241)

builder.paragraph_format.alignment = aw.ParagraphAlignment.CENTER
builder.font.size = 16
builder.font.name = "Arial"
builder.font.bold = True

# Configuring the formatting options in a document builder will apply them
# to the current cell/row its cursor is in,
# as well as any new cells and rows created using that builder.
builder.write("Header Row,\n Cell 1")
builder.insert_cell()
builder.write("Header Row,\n Cell 2")
builder.insert_cell()
builder.write("Header Row,\n Cell 3")
builder.end_row()

# Reconfigure the builder's formatting objects for new rows and cells that we are about to make.
# The builder will not apply these to the first row already created so that it will stand out as a header row.
builder.cell_format.shading.background_pattern_color = drawing.Color.white
builder.cell_format.vertical_alignment = aw.tables.CellVerticalAlignment.CENTER
builder.row_format.height = 30
builder.row_format.height_rule = aw.HeightRule.AUTO
builder.insert_cell()
builder.font.size = 12
builder.font.bold = False

builder.write("Row 1, Cell 1.")
builder.insert_cell()
builder.write("Row 1, Cell 2.")
builder.insert_cell()
builder.write("Row 1, Cell 3.")
builder.end_row()
builder.insert_cell()
builder.write("Row 2, Cell 1.")
builder.insert_cell()
builder.write("Row 2, Cell 2.")
builder.insert_cell()
builder.write("Row 2, Cell 3.")
builder.end_row()
builder.end_table()

doc.save(ARTIFACTS_DIR + "DocumentBuilder.build_formatted_table.docx")

Shows how to format rows with a document builder.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

table = builder.start_table()
builder.insert_cell()
builder.write("Row 1, cell 1.")

# Start a second row, and then configure its height. The builder will apply these settings to
# its current row, as well as any new rows it creates afterwards.
builder.end_row()

row_format = builder.row_format
row_format.height = 100
row_format.height_rule = aw.HeightRule.EXACTLY

builder.insert_cell()
builder.write("Row 2, cell 1.")
builder.end_table()

# The first row was unaffected by the padding reconfiguration and still holds the default values.
self.assertEqual(0.0, table.rows[0].row_format.height)
self.assertEqual(aw.HeightRule.AUTO, table.rows[0].row_format.height_rule)

self.assertEqual(100.0, table.rows[1].row_format.height)
self.assertEqual(aw.HeightRule.EXACTLY, table.rows[1].row_format.height_rule)

doc.save(ARTIFACTS_DIR + "DocumentBuilder.set_row_formatting.docx")

See Also