test.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:reportlab 作者: xiaozheya 项目源码 文件源码
def rpt():
    story = []
    #??????????reportlab-userguide.pdf?chapter 6 Paragraph
    if READ_TYPE == 1:           #?????????
        rpt_title = '<para autoLeading="off" fontSize=10.5 align=center>'+Read.news_title+'<br/></para>'
        story.append(Paragraph(rpt_title, styleH))
        table_list=[]
        temp=[]
        temp.append(Read.news_author)
        temp.append(Read.news_time)
        table_list.append(temp)
        first_table = Table(table_list,colWidths=[225,225])
        first_table.setStyle(TableStyle([
        ('FONTNAME', (0, 0), (1, 0), 'msyhbd'),
        ('ALIGN', (1, 0), (1, 0), 'RIGHT'),  # ???
        ('ALIGN', (0, 0), (0, 0), 'LEFT'),
        ('FONTSIZE', (1, 2), (-1, -1), 10.5),  # ????
        ('TEXTCOLOR', (0, 0), (1, 0), colors.standardfl),
        ]))
        story.append(first_table)
        news_content_list=Read.news_content.splitlines()
        for i in range(len(news_content_list)):
            text = ''
            text += '<para autoLeading="off" fontSize=10.5 ><font face="msyh" >'
            text+=news_content_list[i]
            text +='</font></para>'
            story.append(Paragraph(text, normalStyle))
    if READ_TYPE==2:                  #??word?????????
        doc = docx.Document('test1.docx')
        length = len(doc.paragraphs)
        rpt_title = '<para autoLeading="off" fontSize=10.5 align=center>' + doc.paragraphs[0].text + '<br/></para>'
        story.append(Paragraph(rpt_title, styleH))
        rpt_title = '<para autoLeading="off" fontSize=10.5 align=right color=rgb(84,141,212)>' + doc.paragraphs[1].text + '<br/></para>'
        story.append(Paragraph(rpt_title, styleH))
        for i in range(2,length):
            text = ''
            if doc.paragraphs[i].style.name=='Heading 3' or doc.paragraphs[i].style.name=='Heading 2'or doc.paragraphs[i].style.name=='Heading 1':
                text+='<para autoLeading="off" fontSize=10.5 ><font face="msyhbd" >'
            else :
                text += '<para autoLeading="off" fontSize=10.5 ><font face="msyh" >'
            text+=doc.paragraphs[i].text
            text +='</font></para>'
            story.append(Paragraph(text, normalStyle))
        #?????????reportlab-userguide.pdf?chapter 7 Table
        table.parse_docx('test1.docx')
        component_data = table.component_data
        component_table = Table(component_data)
        component_table.setStyle(table_style.table_style)
        story.append(component_table)

    doc = SimpleDocTemplate('D:/HX/reportlab/bug1.pdf')
    doc.build(story)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号