【问题标题】:How can I set row height in a table to be fixed in python-docx?如何设置表格中的行高以在 python-docx 中修复?
【发布时间】:2017-06-19 09:13:03
【问题描述】:

我正在尝试使用文档中的此示例将行高设置为固定值。

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

(链接中断时的内容)

>>> 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)

但是,我无法从 docx.enum.table 导入 WD_ROW_HEIGHT,出现此错误:

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'

查看源码,table.py 文件在那里,但只有WD_TABLE_ALIGNMENTWD_TABLE_DIRECTION 在里面。

我的 python-docx 版本是 0.8.6

【问题讨论】:

    标签: python docx python-docx


    【解决方案1】:

    您提到的链接实际上是未来的功能(即尚未实现)。

    【讨论】:

    • 这完美地回答了我的问题。如果有任何关于何时实施的想法会很有用,但我意识到可能没有。
    猜你喜欢
    • 1970-01-01
    • 2019-04-11
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    • 2021-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多