Is there a way to write formatted text from Python?

与世无争的帅哥 提交于 2019-12-05 04:46:36

Just been playing around with this assuming MS word, I found that you needed to wrap the document in '{}' and define the doctype, then start bold with '\b' and end with '\b0'. An example would be

test = 'tester.rtf'
out_file = open(test,'w')
out_file.write("""{\\rtf1
This is \\b Bold  \\b0\line\
}""")
out_file.close() #thanks to the comment below

Note the double '\' since python has special meanings for '\b' and '\r'.

The full info came from http://www.pindari.com/rtf1.html, which also describes italics, font etc.

Let me know if that worked for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!