Python ReportLab LongTable Layouter错误:第页太大

Python ReportLab LongTable Layouter错误:第页太大,python,pdf-generation,reportlab,platypus,Python,Pdf Generation,Reportlab,Platypus,我使用LongTables来显示表格数据,但当行高度超过页面高度时,它会崩溃 File "c:\edat\19_with_edm\fiods\..\fiods\reporting\pdf_utils.py", line 1497, in build_table doc.build(story, canvasmaker=NumberedCanvas) File "C:\Python27\lib\site-packages\reportlab\platypus\doctemplat

我使用LongTables来显示表格数据,但当行高度超过页面高度时,它会崩溃

  File "c:\edat\19_with_edm\fiods\..\fiods\reporting\pdf_utils.py", line 1497, in build_table
    doc.build(story, canvasmaker=NumberedCanvas)

  File "C:\Python27\lib\site-packages\reportlab\platypus\doctemplate.py", line 880, in build
    self.handle_flowable(flowables)

  File "C:\Python27\lib\site-packages\reportlab\platypus\doctemplate.py", line 793, in handle_flowable
    raise LayoutError(ident)

LayoutError: Flowable <LongTable@0x018DB0A8 30 rows x 20 cols> with cell(0,0) containing
'Eq\nLvl\nD'(756.0 x 967.6) too large on page 2 in frame 'edat_table_frame'(756.0 x 504.0*) of template 'edat_page_template'
文件“c:\edat\19\u与\u edm\fiods\..\fiods\reporting\pdf\u utils.py”,第1497行,在构建表中
doc.build(故事,canvasmaker=NumberedCanvas)
文件“C:\Python27\lib\site packages\reportlab\platypus\doctemplate.py”,第880行,内部版本
自身手柄可流动(可流动)
文件“C:\Python27\lib\site packages\reportlab\platypus\doctemplate.py”,第793行,在handle\u flowable中
升起布局器错误(识别)
LayoutError:可流动,单元格(0,0)包含
“Eq\nLvl\nD”(756.0 x 967.6)在模板“edat_page_template”的框架“edat_table_frame”(756.0 x 504.0*)的第2页上太大

错误看起来像是您试图格式化表格,如果框架在单个页面中,则超出了限制。我用“Table”和“LongTable”测试了一段代码,只要您不试图同时格式化第一页和第二页,它就会在多个页面上显示数据

示例代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from reportlab.platypus import SimpleDocTemplate, Table, LongTable, TableStyle, BaseDocTemplate, Frame, Paragraph, NextPageTemplate, PageTemplate
from reportlab.lib.pagesizes import letter, inch
from reportlab.lib import colors

def testPdf():
    doc = BaseDocTemplate("testpdf.pdf",pagesize=letter,
                        rightMargin=72,leftMargin=72,
                        topMargin=72,bottomMargin=18, showBoundary=True)
width, height = letter
print width 
print height

elements = []
datas = []
for x in range(1,50):
    datas.append(
        [x,x+1]
    )
t=LongTable(datas)

tTableStyle=[
    ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
    ('BOX', (0,0), (-1,-1), 0.25, colors.black),
  ]
t.setStyle(TableStyle(tTableStyle))
elements.append(t)

frameT = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height, id='normal')

doc.addPageTemplates([PageTemplate(id='OneCol',frames=frameT)])

doc.build(elements)

if __name__ == '__main__':
    testPdf()
如果您将表格格式化为:

tTableStyle=[
    ('SPAN',(0,0),(0,38), #span over the frame limit
    ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
    ('BOX', (0,0), (-1,-1), 0.25, colors.black),
  ]
那么您将遇到此错误。我想说最好的方法可能是手动格式化表格,但我希望有更好的解决方案