当前位置: 首页>>代码示例>>Python>>正文


Python Table.canvas方法代码示例

本文整理汇总了Python中reportlab.platypus.Table.canvas方法的典型用法代码示例。如果您正苦于以下问题:Python Table.canvas方法的具体用法?Python Table.canvas怎么用?Python Table.canvas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reportlab.platypus.Table的用法示例。


在下文中一共展示了Table.canvas方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createPDF

# 需要导入模块: from reportlab.platypus import Table [as 别名]
# 或者: from reportlab.platypus.Table import canvas [as 别名]
    def createPDF(self):
        xml = self.xml_obj
        styles = getSampleStyleSheet()
        styles = styles['BodyText']
        styles.wordWrap = 'CJK'

        # Example user
        users = {'U00000000': 'bogeunchoi'}

        data = []
        data.append(['Channel: ' + channelName])
        data.append(["User", "Time", "Message (top = newest)"])

        for item in xml.data.iterchildren():
            # Creating name column
            row = []
            row.append(item.name)

            # Creating time column
            s = item.time
            date = datetime.datetime.fromtimestamp(s).strftime('%Y-%m-%d %H:%M:%S')
            row.append(date)

            # Creating message column
            if ('’' in item.message.text):
                item.message.text = item.message.text.replace('’', '\'')

            text = item.message.text

            # Filtering out the @U0... and replacing with usernames
            for key, value in users.items():
                keyPlus = key + '|'
                if keyPlus in text:
                    text = text.replace(keyPlus, "")
                elif key in text:
                    text = text.replace(key, value)

            text = filter(lambda c: c not in "<>", text)

            message = Paragraph(text, styles)
            row.append(message)

            data.append(row)

        t = Table(data, colWidths=(75, 110, 100*mm), hAlign='CENTER')
        t.setStyle(TableStyle([
            ('INNERGRID', (0, 0), (-1, -1), 0.5, colors.black),
            ('BOX', (0, 0), (-1, -1), 0.5, colors.black),
            ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
            ('SPAN', (0, 0), (-1, 0))
        ]))
        width, height = t.wrap(0, 0)
        w = width
        h = height

        self.canvas = canvas.Canvas(self.pdf_file, pagesize=(w, h))
        width, self.height = letter

        t.wrapOn(self.canvas, width, self.height)
        t.drawOn(self.canvas, 0, 0)
        t.canvas = self.canvas
开发者ID:TheJPFDude,项目名称:slack-data-grabber,代码行数:63,代码来源:xml_to_pdf.py


注:本文中的reportlab.platypus.Table.canvas方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。