猫史档案馆


【Python作品分享】表格【作品秀】

用户:yj皓月当空yj皓月当空查看:0 回复:0 评论:0 创建时间:2020-03-26T15:02:08


【作品展示】

center_image

 

【作品介绍】

0

 

【作品源代码】

from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
from reportlab.lib import colors
import webbrowser
import os
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont

# pdfmetrics.registerFont(TTFont('fangzheng', 'fangzheng.TTF'))

doc = SimpleDocTemplate("源码表格.pdf")
content = []
data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
t = Table(data, colWidths=100, rowHeights=100)  # 创建表格
t.setStyle(TableStyle([
    (("TEXTCOLOR"), (-1, -1), (-1, -1), colors.red),
    (("INNERGRID"), (0, 0), (-1, -1), 2, colors.red),
    (("BOX"), (0, 0), (-1, -1), 2, colors.black),
    (("ALIGN"), (0, 0), (-1, -1), 'CENTER'),
    (("VALIGN"), (0, 0), (-1, -1), 'MIDDLE'),
    (("FONTSIZE"), (0, 0), (-1, 0), 10),
    (("FONTSIZE"), (0, -2), (-1, -2), 15),
    (("FONTSIZE"), (0, -1), (-1, -1), 20),
]))
content.append(t)  # 表格加入内容列表

doc.build(content)
webbrowser.open("file://" + os.path.realpath("源码表格.pdf"))

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页