Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Python to output bold text in .doc

I am trying to print this statement:

a= 'Hi %s, \n The meeting is scheduled for %s %sth \n if you have an  questions please contact %s' % (cfname, meetingmonth, meetingday, cleadfname)
print a

I'm also trying to bold every variable insert (i.e. cfname, meetingmonth etc.). Basically, I have a script asking the enduser for input which writes this statement to a .doc format. Is there a simple way to bold things when writing something in python?

I've tried the bold brackets around the word and that doesn't seem to work. Any help would be great!

like image 933
user3527972 Avatar asked Mar 21 '26 11:03

user3527972


2 Answers

print produces plain text, not Microsoft Word documents. If you add HTML formatting tags (<html>, <body>, <strong>, <br />, etc.) where necessary, then give the resulting text file the .doc extension, it will open with Word, which - assuming you have a reasonably recent version that understands HTML - will parse the HTML and display the result you're looking for.

Sample:

a= '<html><head></head><body>Hi %s, </br> The meeting is scheduled for <strong>%s %sth</strong> <br /> if you have an  questions please contact %s</body></html>' % (cfname, meetingmonth, meetingday, cleadfname)
like image 103
TigerhawkT3 Avatar answered Mar 22 '26 23:03

TigerhawkT3


try using termcolor

>>> from termcolor import cprint
>>> cprint("Hello", attrs=['bold'])
like image 36
Rameshkumar R Avatar answered Mar 23 '26 01:03

Rameshkumar R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!