2012-03-29 203 views
3

上,但是當行高更則頁面高度將其與ReportLab的LongTable LayoutError:太大我使用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 <[email protected] 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' 

回答

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), 
    ] 

然後你就會碰到這個錯誤。我想說最好的方法是手動格式化表格,但我希望有更好的解決方案。