如何旋转表格单元格中的文本?

Дми*_*нко 4 python-docx

我正在尝试制作这样的表格:

具有垂直标题单元格的表格

如您所见,标题是垂直方向的。如何使用 python-docx 实现此目的?

PS 抱歉未翻译表格。

Mad*_*ash 5

给那些太累而无法寻找的人的片段:

from docx.oxml import OxmlElement
from docx.oxml.ns import qn
from docx.table import _Cell


def set_vertical_cell_direction(cell: _Cell, direction: str):
    # direction: tbRl -- top to bottom, btLr -- bottom to top
    assert direction in ("tbRl", "btLr")
    tc = cell._tc
    tcPr = tc.get_or_add_tcPr()
    textDirection = OxmlElement('w:textDirection')
    textDirection.set(qn('w:val'), direction)  # btLr tbRl
    tcPr.append(textDirection)
Run Code Online (Sandbox Code Playgroud)