I am trying to replacing the text using loop on doc.paragrapgh .I got success in replacing the text ,but the images got removed .I want to preserve the images and only want to replace the text . Thanks in advance i am using below code for the same
from docx import Document
from docx.table import _Cell
doc = Document("abc.docx")
for p in doc.paragraphs:
if 'CORREDOR' in p.text:
text = p.text.replace(p.text, "VIGENCIA").strip()
style = p.style
p.text = text
p.style = style
elif 'DECLARACIóN DE NO SINIESTRALIDAD' in p.text:
text= p.text.replace(p.text, "DECLARACIóN DE SINIESTRALIDAD")
style = p.style
p.text = text
p.style = style
doc.save('result4.docx')
question from:
https://stackoverflow.com/questions/65843126/how-to-extract-text-and-images-from-a-docx-file-and-write-it-to-new-docx-file-wi 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…