estoy aprendiendo a programar en Python y estoy haciendo un función simple con Tkinter para ingresar datos y que se reemplacen en un .docx, venía funcionando todo con normalidad hasta que comencé a trabajar con tablas, ahí fue cuando ya no supe como seguir, reemplaza el texto correctamente, no reemplaza en las tablas, alguna sugerencia? Muchas gracias.
def docx_find_replace_text(doc, search_text, replace_text):
paragraphs = list(doc.paragraphs)
for t in doc.tables:
for row in t.rows:
for cell in row.cells:
for paragraph in cell.paragraphs:
paragraphs.append(paragraph)
for p in paragraphs:
if search_text in p.text:
inline = p.runs
started = False
search_index = 0
found_runs = list()
found_all = False
replace_done = False
for i in range(len(inline)):
if search_text in inline[i].text and not started:
found_runs.append((i, inline[i].text.find(search_text), len(search_text)))
text = inline[i].text.replace(search_text, str(replace_text))
inline[i].text = text
replace_done = True
found_all = True
break