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:
but the result is
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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' ) |
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