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')