Search code examples
pythondocxpython-docx

How can I set row height in a table to be fixed in python-docx?


I'm trying to use this example from the documentation to set the row height to be a fixed value.

http://python-docx.readthedocs.io/en/latest/dev/analysis/features/table/table-row.html?highlight=table#row-height

(Content in case link breaks)

>>> from docx.enum.table import WD_ROW_HEIGHT
>>> row = table.add_row()
>>> row
<docx.table._Row object at 0x...>
>>> row.height_rule
None
>>> row.height_rule = WD_ROW_HEIGHT.EXACTLY
>>> row.height
None
>>> row.height = Pt(24)

However, I can't import WD_ROW_HEIGHT from docx.enum.table giving this error:

Traceback (most recent call last):
  File "C:/Users/Calderdale NUT/Google Drive/CDFU/Membership Python/labels test.py", line 2, in <module>
    from docx.enum.table import WD_ROW_HEIGHT
ImportError: cannot import name 'WD_ROW_HEIGHT'

Checking the source, the table.py file is there, but only has WD_TABLE_ALIGNMENT and WD_TABLE_DIRECTION in.

My python-docx version is 0.8.6


Solution

  • The link you referred to is in fact future features (i.e. not yet implemented).