Buenos días. Cómo les va?
Les comento, estoy aprendiendo Python y estoy intentando agilitar mi trabajo con docx, pero estoy teniendo un pequeño problema el cual no logro solventar, resulta que cuando reemplazo un texto, se me cambia la fuente de “Times New Roman” a “Calibri”
Estuve intentando asignarle la font mediante Style pero nada, alguna sugerencia?
Desde ya muchas gracias.
for paragraph in document.paragraphs:
if "{{dia}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{dia}}", dia.get())
"""style = document.styles['Normal']
ffont = style.font
ffont.name = "Times New Roman" """
if "{{mes}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{mes}}", mes.get())
if "{{año}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{año}}", año.get())
if "{{grado}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{grado}}", grado_1.get())
if "{{pnombre}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{pnombre}}", pnombre_1.get())
if "{{snombre}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{snombre}}", snombre_1.get())
if "{{papellido}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{papellido}}", papellido_1.get())
if "{{sapellido}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{sapellido}}", sapellido_1.get())
if "{{ci}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{ci}}", cedula_1.get())
if "{{gradomed}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{gradomed}}", medencargado_gr.get())
if "{{nombremed}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{nombremed}}", medencargado_nombre.get())
if "{{ofgrado}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{ofgrado}}", ofencargado_gr.get())
if "{{ofnombre}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{ofnombre}}", ofencargado_nombre.get())
if "{{dt}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{dt}}", dia.get())
if "{{hora}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{hora}}", hora.get())
if "{{mess}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{mess}}", mes.get()[:3].upper())
if "{{añoo}}" in paragraph.text:
paragraph.text = paragraph.text.replace("{{añoo}}", año.get()[-2:])
print(año.get()[-2:])
document.save(f"Formularios estupefacientes/Formulario Nº 1 (Toma de muestra) {pnombre_1.get()} {papellido_1.get()}.docx")