python 写一些报告,常用的可用win32 com的模块编写WORD,不过不能居于linux平台,这里采用PyRTF模块来生成rtf。对一些基础操作,做些记录!脚本可以优化,对于一些调用可以写成函数形式,这里是为了理解方便!
注意:参考PyRTF模块实例
#!/usr/bin/python
#--Pyrtf example 1
import sys
sys.path.append('/home/tanght/PyRTF-0.45')
from PyRTF import *
##sample file
SAMPLE_TEXT='''THIS IS A SAMPLE PARAGRAPH
THIS IS A SAMPLE PARAGRAPH
THIS IS A SAMPLE PARAGRAPH
THIS IS A SAMPLE PARAGRAPH'''
def pyrtfexample1():
##style
doc = Document()
handle = doc.StyleSheet
section = Section()
doc.Sections.append(section)
##Set Header,Footer
section.Header.append('THIS IS THE HEADER')
section.Footer.append('THIS IS THE FOOTER')
##Title Font
pa = Paragraph(handle.ParagraphStyles.Heading1)
pa.append('USAGE OF PyRTF')
section.append(pa)
##Content Font
pa = Paragraph(handle.ParagraphStyles.Normal)
pa.append('This is an example by using Py

这篇博客介绍了如何在Python中利用PyRTF模块生成RTF文件,特别适用于跨平台的报告编写。文中通过简单的示例,展示了创建和优化RTF文档的基础操作。
最低0.47元/天 解锁文章
1283

被折叠的 条评论
为什么被折叠?



