Python-docx缩进2字符如何实现?

word中我们最常用的一种格式就是首行缩进2字符,但在python-docx里面缩进单位只有Pt、Cm、Inches三种。在网上查找了一些方法,经试验只能根据字体的大小去设置。如5号中文字体对应10.5pt,则先设置字体大小为10.5pt,然后再设置首行缩进字体大小*2。代码如下:

from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx import Document
from docx.shared import Inches,Pt,Cm

doc = Document()
para = doc.add_paragraph('伟大光荣正确的中国共产党万岁'*20)
para.style.font.size = Pt(10.5)
para.paragraph_format.first_line_indent = para.style.font.size*2

运行后结果如下:

附上常见的中文字号与磅数和厘米的对照表:

序号字号ptcm
1大特号632.2142
2特号541.8979
3初号421.4761
4小初号361.2653
5大一号31.51.1071
6一号280.9841
7二号210.7381
8小二号180.6326
9三号160.5623
10四号140.4920
11小四号120.4218
12五号10.50.3690
13小五号90.3163
14六号80.2812
15小六号6.8750.2416
16七号5.250.1845
17八号4.50.1581

You may also like...

5 Responses

  1. 2023-03-13

    <strong>tadalafil 5mg https://pudbiascan.strikingly.com/</strong&gt;

    Fine material. With thanks.

  2. 2023-05-13

    Discount viagra https://shippingtousa.mystrikingly.com/

    Truly all kinds of very good knowledge!

  3. 2023-05-15
  4. 2023-05-17

    Online viagra http://trommelforum.ch/forum/profile/franbervage/

    Terrific stuff, Thanks.

  5. 2023-05-20

    Tadalafil tablets https://chanchuoi.com/community/profile/canadianpharmacy/

    Great information. Thanks a lot!

发表回复