关于本站
基于Django+Bootstrap开发
主要发表本人使用过的技术
于 2023-12-01 搭建本站
def set_indent(paragraph, left_indent=None, right_indent=None, first_line_indent=None, hanging_indent=None):
"""
设置缩进,单位为字符
:param paragraph: 段落
:param left_indent: 左缩进
:param right_indent: 右缩进
:param first_line_indent: 首行缩进, 大于0
:param hanging_indent: 悬挂缩进,小于0
"""
assert not all([first_line_indent, hanging_indent]), '首行缩进与悬挂缩进不可同时设置'
pPr = paragraph._element.get_or_add_pPr()
ind = OxmlElement('w:ind')
if left_indent:
ind.set(qn('w:leftChars'), str(left_indent * 100))
if right_indent:
ind.set(qn('w:rightChars'), str(right_indent * 100))
if first_line_indent:
ind.set(qn('w:firstLineChars'), str(first_line_indent * 100))
if hanging_indent:
ind.set(qn('w:hangingChars'), str(hanging_indent * 100))
pPr.append(ind)
提交评论
您尚未登录,登录之后方可评论~ 登录 or 注册