How to use Worksheet.StandardHeight in the xlwings API way

The StandardHeight property in the Excel object model, accessible through the Worksheet object, refers to the standard (default) row height for the worksheet, measured in points. This value is typically set based on the default font size of the workbook’s normal style. In xlwings, you can retrieve this property to understand or utilize the baseline row height for formatting or layout calculations. It is a read-only property, meaning you cannot directly set it to change the default row height; instead, you would adjust row heights individually or modify the normal style’s font.

Syntax in xlwings:

worksheet.api.StandardHeight
  • worksheet: An xlwings Sheet object representing the Excel worksheet.
  • .api: This attribute provides access to the underlying Excel object model (via pywin32 on Windows or appscript on macOS).
  • StandardHeight: The property that returns a float value representing the standard height in points.

Example Usage:
Suppose you want to compare the current height of a specific row (e.g., row 5) with the standard row height to determine if it has been customized. You can use the StandardHeight property in conjunction with the RowHeight property.

import xlwings as xw

# Connect to an existing workbook and worksheet
wb = xw.Book("example.xlsx")
ws = wb.sheets["Sheet1"]

# Get the standard row height
standard_height = ws.api.StandardHeight
print(f"Standard row height: {standard_height} points")

# Get the height of row 5
row5_height = ws.range("5:5").row_height
print(f"Row 5 height: {row5_height} points")

# Compare and provide feedback
if row5_height == standard_height:
    print("Row 5 uses the standard height.")
else:
    print(f"Row 5 is customized. Difference: {row5_height - standard_height} points.")

# Close the workbook (optional, based on your workflow)
wb.close()

October 5, 2026 (0)


Leave a Reply

Your email address will not be published. Required fields are marked *