python docx 学习笔记 paragraph

paragraph学习笔记

  1. 修改段落格式属性
    修改段落格式使用段落的paragraph_format属性,会生成一个 ParagraphFormat对象
  2. 设置段落对齐方式
document = Document()
p = document.add_paragraph()
pFormat = p.paragraph_format
pFormat.alignment = WD_ALIGN_PARAGRAPH.JUSTIFY
#对齐方式包括: left, centered, right, or fully justified
p.add_run('hello,world')
  1. 设置段落缩进方式
#1.段落整体缩进
paragraph_format.left_indent = Inches(0.5)
#2.段落整体右缩进
paragraph_format.left_indent = Pt(24)
#3.段落首行缩进用first_line_indent属性指定
pFormat.first_line_indent = Pt(24)
  1. 设置段落前后间距
#1.段前间距
paragraph_format.space_before = Pt(18)
#2.段后间距
paragraph_format.space_after = Pt(12)
  1. 设置行间距
#设置行间距可以设置为绝对值和相对值(相对于字体大小)
#所用到的属性为line_spacing 和 line_spacing_rule(枚举类型)
#line_spacing_rule包括:SINGLE, DOUBLE, or ONE_POINT_FIVE
#line_spacing为整数时,表示绝对值,为浮点数时,表示相对值
paragraph_format.line_spacing = 1.75
#line_spacing_rule的值为WD_LINE_SPACING的属性
paragraph_format.line_spacing_rule = WD_LINE_SPACING.DOUBLE
  1. 设置分页
#设置分页使用属性keep_together, keep_with_next, page_break_before, and widow_control

posted on   朝朝暮Mu  阅读(655)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示