使用 Python 在 .doc 中输出粗体文本
Use Python to output bold text in .doc
我正在尝试打印此语句:
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
我还尝试将每个变量插入(即 cfname、meetingmonth 等)加粗。基本上,我有一个脚本要求最终用户输入,该脚本将此语句写入 .doc 格式。在 python?
中写东西时,有没有简单的方法来加粗?
我试过用粗体括号括起这个词,但似乎不起作用。任何帮助都会很棒!
print
生成纯文本,而不是 Microsoft Word 文档。如果您在必要时添加 HTML 格式标记(<html>
、<body>
、<strong>
、<br />
等),则为生成的文本文件提供 .doc
扩展名,它将用 Word 打开,假设您有一个理解 HTML 的相当新的版本 - 将解析 HTML 并显示您正在寻找的结果。
样本:
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)
您可能会成功使用帮助 python 输出富文本格式的模块,例如 PyRTF。
但是,有人建议 HTML 更容易使用:
Fonts formatting in python output
尝试使用 termcolor
>>> from termcolor import cprint
>>> cprint("Hello", attrs=['bold'])
我正在尝试打印此语句:
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
我还尝试将每个变量插入(即 cfname、meetingmonth 等)加粗。基本上,我有一个脚本要求最终用户输入,该脚本将此语句写入 .doc 格式。在 python?
中写东西时,有没有简单的方法来加粗?我试过用粗体括号括起这个词,但似乎不起作用。任何帮助都会很棒!
print
生成纯文本,而不是 Microsoft Word 文档。如果您在必要时添加 HTML 格式标记(<html>
、<body>
、<strong>
、<br />
等),则为生成的文本文件提供 .doc
扩展名,它将用 Word 打开,假设您有一个理解 HTML 的相当新的版本 - 将解析 HTML 并显示您正在寻找的结果。
样本:
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)
您可能会成功使用帮助 python 输出富文本格式的模块,例如 PyRTF。
但是,有人建议 HTML 更容易使用:
Fonts formatting in python output
尝试使用 termcolor
>>> from termcolor import cprint
>>> cprint("Hello", attrs=['bold'])