如何使用 python-docx 删除段落之间的空格?

时间:2021-01-09 21:40:12

标签: python python-3.x python-docx

我正在尝试制作一个简单的脚本来创建 .docx 文档。 我在 python 3.7 的窗口环境中使用 python-docx 库。

当我在单词的标题中添加一个 .png 然后再添加一个段落时。我在单词中看到一个段落和另一个段落之间有一个空格。 我想看看你是否能帮我弄清楚如何消除这种情况。下面是我的代码和空间的图像。

from docx import Document
from docx.shared import Inches, Pt
import os, datetime

doc = Document("plantilla.docx")
coreprops = doc.core_properties
props = dir(coreprops)
coreprops.author = "Osiris Quintero"
coreprops.comments = "Este archivo documenta las instalaciones de cliente por radio enlace"
coreprops.revision = 2
coreprops.created = datetime.datetime.now()

style = doc.styles['Normal']
font = style.font
font.name = 'Calibri'
font.size = Pt(14)

direction = r'C:\Users\Mats_\Pictures\logo.png'
header = doc.sections[0].header
paragraph = header.paragraphs[0]
logo_run = paragraph.add_run()
logo_run.add_picture(direction, width=Inches(1.85))

titule = doc.add_paragraph()
titule_1 = titule.add_run()
titule_1.add_text("test")

doc.save('path_to_document.docx')
os.startfile(r'D:\proyectos de python\crear_archivo_de_word_para_osiris\path_to_document.docx')

输出: current output

0 个答案:

没有答案