如何使用pythondocx删除段落之间的空格?

2024-10-01 22:25:54 发布

您现在位置:Python中文网/ 问答频道 /正文

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

当我在单词的标题中添加.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


Tags: runimportadddatetimedocpngde单词

热门问题