Splitting ReportLab table across PDF page (side by side)?

三世轮回 提交于 2019-12-08 19:28:28

If you know the exact number of rows on the page you can use this function to simulate two columns. That way the the table still automatically flows over multiple pages and you don't have to worry about PageTemplates.

def columnize(data, interval):
    ret = []
    for i in range(0, len(data), interval * 2):
        for j in range(min(interval, len(data) - i)):
            ret.append(data[i + j] + (data[i + j + interval] if i + j + interval < len(data) else []))
    return ret

Use in your example:

data = columnize(data, 75)
tableThatSplitsOverPages = Table(data, [2.5 * cm, 2.5 * cm], repeatRows=1)

You will need to use PageTemplates to accomplish this by creating a PageTemplate that has multiple Frames that will allow you to specify content areas to draw the document within the page. This unfortunately means abandoning SimpleDocTemplate and instead using BaseDocTemplate and supplying your own PageTemplates (as well as other things if you want them).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!