使用reportlab生成长表pdf [英] Generating a pdf of long tables with reportlab

查看:129
本文介绍了使用reportlab生成长表pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理从大量数据列表中生成PDF的问题.

I am dealing with generating a PDF from a huge data list.

不涉及任何花哨的样式或格式.只是数据是一个巨大的列表(大约500行500列).这是我的代码.目前,根据页面大小将行划分到多个页面上没有问题,但是由于500个列不能容纳在一个页面中,因此该列已被切断.我也想在不同页面上拆分列.每个单元格条目只是一个整数.我该如何实现?

There is no fancy styling or formatting involved. It's just that the data is a huge list (about 500 rows and 500 columns). Here is my code. Currently it will have no problem splitting rows across multiple pages depending on the page size, but the columns are being cut off since 500 columns don't fit in one page. I would also like to split columns across different pages as well. Each cell entry is just an integer. How can I achieve that?

from reportlab.lib import colors
from reportlab.lib.units import cm
from reportlab.lib.pagesizes import A0
from reportlab.platypus import SimpleDocTemplate, LongTable, TableStyle


elements = []
doc = SimpleDocTemplate(output, pagesize=A0)
t = LongTable(data)
t.setStyle(TableStyle([('INNERGRID', (0,0), (-1, -1), 0.25, colors.black), 
                       ('BOX', (0, 0), (-1, -1), 0.25, colors.black), 
                     ]))
elements.append(t)
doc.build(elements)

推荐答案

我认为PDF打印的最佳选择可能是实际上声明一个足以处理数据的页面大小.例如,如果网格的每个块都为1x1英寸,每边的填充为1英寸,则尝试执行以下操作:

I think the best option for a PDF print might be to actually declare a pagesize large enough to handle the data. For instance if each block of the grid is 1x1 inch and one inch padding on each side, then try doing something like:

doc = SimpleDocTemplate(output, pagesize=(502*inch, 502*inch) )

这篇关于使用reportlab生成长表pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆