0

I have a Word DOCX that contains a table and by using Python script I want to find-and-replace specific text. So far any solution I found and tried did not work. Here is a sample screenshot of my Word DOCX that I am working on enter image description here

I would like to replace the text to_be_replaced with something else. Can someone please help me out? Thank you

sugarakis
  • 117
  • 9
  • Try looking at [Replace text in docx tables in Python 3](https://stackoverflow.com/questions/40369351/replace-text-in-docx-tables-in-python-3). – Alias Cartellano Mar 07 '23 at 20:36
  • @Cartellano I have seen this solution before but unfortunately I could not figure out the right coding for it. – sugarakis Mar 07 '23 at 20:41

1 Answers1

0

After some more surfing I finally found the source code that works like a charm!!!

Python docx Replace string in paragraph while keeping style

The code snipet that I used and worked for me was the answer by:

enter image description here

The Word docx I used contained tables and images and the code just replaced the words I wanted, without changing anything else in the document. Really good work by CG Zhang. I hope my answer helps others too.

sugarakis
  • 117
  • 9