2011-11-01 7 views
1

예 : 테이블이 한 페이지에 있기 때문에 나는 "SPAN"을 "(0,0)을 설정하면Reportlab : 사용 테이블 및 SPAN

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

from reportlab.platypus import SimpleDocTemplate, Table, TableStyle 
from reportlab.lib.pagesizes import letter 

def testPdf(): 
    doc = SimpleDocTemplate("testpdf.pdf",pagesize=letter, 
         rightMargin=72,leftMargin=72, 
         topMargin=72,bottomMargin=18) 
    elements = [] 
    datas = [] 
    for x in range(1,50): 
     datas.append(
      [x,x+1] 
     ) 
    t=Table(datas) 
    tTableStyle=[ 
     ('SPAN',(0,0),(0,37)), 
     ] 
    t.setStyle(TableStyle(tTableStyle)) 
    elements.append(t) 
    doc.build(elements) 

if __name__ == '__main__': 
    testPdf() 

이 코드는, 성공을 실행 (0.38

reportlab.platypus.doctemplate.LayoutError: Flowable with cell(0,0) containing
'1'(46.24 x 702) too large on page 2 in frame 'normal'(456.0 x 690.0*) of template 'Later'

그리고 나는 그것이 더 큰 설정하면 오류는 다음과 같습니다 :) "오류입니다

Traceback (most recent call last): 
    File "testpdf.py", line 26, in <module> 
    testPdf() 
    File "testpdf.py", line 23, in testPdf 
    doc.build(elements) 
    File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/doctemplate.py", line 1117, in build 
    BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker) 
    File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/doctemplate.py", line 880, in build 
    self.handle_flowable(flowables) 
    File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/doctemplate.py", line 763, in handle_flowable 
    if frame.add(f, canv, trySplit=self.allowSplitting): 
    File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/frames.py", line 159, in _add 
    w, h = flowable.wrap(aW, h) 
    File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/tables.py", line 1113, in wrap 
    self._calc(availWidth, availHeight) 
    File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/tables.py", line 587, in _calc 
    self._calc_height(availHeight,availWidth,W=W) 
    File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/tables.py", line 553, in _calc_height 
    spanFixDim(H0,H,spanCons,lim=hmax) 
    File "/usr/local/lib/python2.7/dist-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/tables.py", line 205, in spanFixDim 
    t = sum([V[x]+M.get(x,0) for x in xrange(x0,x1)]) 
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int' 

어떻게이 처리 할 수 ​​있습니까?

+1

어떤 행동을보고 싶습니까? 예상되는 정확한 이유로이 오류가 발생합니다. 표 셀이 너무 커서 단일 프레임에 표시 할 수 없습니다. 프레임을 어떻게 든 더 크게 만들거나 셀을 분할해야합니다. –

+0

페이지에 "SPAN"을 자동으로 만들 수있는 방법이 있습니까? – Danfi

+0

내가 아는 것은 아닙니다. 나는 세포가 어떻게 작동하는지에 근본적으로 반대한다고 확신합니다. –

답변

1

이 문제가 발생하는 이유는 바로 Gordon Worley가 위에 언급 한 이유입니다. 알고리즘 구현시 높이와 너비가 혼동되므로 자동으로 페이지를 가로 지르는 방법이 없습니다.

이 문제를 해결하기위한 방법은 행/열 좌표를 사용하여 페이지 당 표를 수동으로 형식 지정/스타일을 지정하는 것입니다. 슬프게도, reportlab의 응답조차도 수동으로이 작업을 수행 할 것을 제안합니다.

필자의 테이블을 수동으로 분할하고 별도로 스타일을 지정했는데, 제 의견으로는 매우 못 생겼습니다. 나중에 다른 대안을 찾아 보겠습니다.

참조 용 : https://bitbucket.org/ntj/reportlab_imko_table

관련 문제