如何旋转 table 单元格中的文本?
How to rotate text in table cells?
我正在尝试使 table 像这样:
如您所见,页眉是垂直放置的。
如何使用 python-docx 实现此目的?
P.S。抱歉未翻译 table.
懒得找的片断:
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)
我正在尝试使 table 像这样:
如您所见,页眉是垂直放置的。 如何使用 python-docx 实现此目的?
P.S。抱歉未翻译 table.
懒得找的片断:
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)