Jul-01-2022, 07:25 AM
In my docx file there are pieces of text i have to process such as making words italic, bold or underlined.
Example
I used this code:
What do I have to do so that the output is
Example
Quote: input: In the future, if you try hard you will fail a lot
I used this code:
from docx import Document import re def change(filename,key): doc = Document(filename) for p in doc.paragraphs: text = p.text split_text = text.split(key) for i in split_text[:-1]: p.add_run(i) font = p.add_run(key).bold = True p.add_run(split_text[-1]) doc.save('test.docx') path = r'path of file' change(path,'key')but the result is
Quote:In the future, if you try hard you will fail a lotIn the future
What do I have to do so that the output is
Quote:output: In the future, if you try hard you will fail a lot