(Sep-19-2021, 01:30 PM)Mr_Blue Wrote: i didn't get something, then.Open file as binary(
because when i try to use just python with a command like file.write(line.replace('this', 'that')) i have an error message
rb
) then there is no encoding problems.You most look at doc or search how replace is done python-docx.
Quick test.
from docx import Document file = open('Hello world.docx', 'rb') document = Document(file) for paragraph in document.paragraphs: if 'Hello' in paragraph.text: print(paragraph.text) # Hello world paragraph.text = paragraph.text.replace("Hello", "Ocean") document.save('result.docx')So now in
result.docx
it will say Ocean world