Answer the question
In order to leave comments, you need to log in
(Python, docx) Why can't I replace a word exactly in the table?
There is this code that replaces "apple" with "apple", but the problem is that the code ignores the word "apple" if it is in the table.. How can I fix this?
import docx
document = docx.Document("one.docx")
for paragraph in document.paragraphs:
paragraph.text = paragraph.text.replace("apple", "яблоко")
document.save("one.docx")
Answer the question
In order to leave comments, you need to log in
You need to pay attention to the structure of the file, in addition to paragraphs in the document, there are tables and headers and footers.
#Таблицы
document.tables
#Заголовки
document.header
#Подвалы
document.footer
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question