Good morning! I need some help ...
I have a word file named ' test.docx '.
I would like to replace each term within it with strings that are in a list. See example.
The problem that is occurring is that the change is not looping.
Can you help me? Thank you in advance!
---- x ----
from docx import Document
caminho = 'D:\Users\89614879\Desktop\Nova pasta\'
arquivo = 'teste.docx'
docword = caminho + arquivo
doc = Document(docword)
lista = [['111','adm','Pedro Paulo'],['222','cont','Luiz Carlos'],['333','econ','Jorge Fernando'],['444','jorn','Claudia Leite']]
qtd_linhas = len(lista)
qtd_colunas = len(lista[0])
nome_arq = ['Pedro Paulo', 'Luiz Carlos', 'Jorge Fernando','Claudia Leite']
for i, paragrafo in enumerate(doc.paragraphs):
palavra = '<' + str(i) + '>'
if palavra in paragrafo.text:
for x in range(qtd_linhas):
for y in range(qtd_colunas):
paragrafo.text = paragrafo.text.replace(palavra, str(lista[x][y]))
new_docword = caminho + nome_arq[y] + '.docx'
doc.save(new_docword)