こんにちは、レポートラボを初めて使用します。表を含む PDF レポートを生成したいと考えています。テーブル内の一部の列テキストが列幅を超えています。列幅に合わせてテキストを折り返す必要があります。
以下は私が書いたコードです
# Imports
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import inch
from reportlab.lib import colors
from reportlab.platypus import Paragraph, Frame, Spacer, Image, Table, TableStyle, SimpleDocTemplate
from reportlab.lib.enums import TA_JUSTIFY, TA_LEFT, TA_CENTER
# My data
result1 = [1,2,3,4,5,6000000000000000000000000000000000000000000000000]
result2 = [10,20,30,40,50,60]
result3 = [100,200,300,400,500,600000000000000000000000000000000000000000000000000]
# create a list and add the elements of our document (image, paragraphs, table) to it
story = []
# define the style for our paragraph text
styles = getSampleStyleSheet()
styleN = styles['Normal']
styleN.alignment = TA_CENTER
styleT = styles['Title']
styleB = styles["BodyText"]
styleB.alignment = TA_LEFT
# first add the Title of the report
pTitle = Paragraph('<font size="30" color="darkblue">Report</font>', styleT)
story.append(pTitle)
story.append(Spacer(1, .5*inch))
# User details
story.append(Paragraph("<font color='darkblue'><b>Name : </b></font>" + "<user name>", styleN))
story.append(Spacer(1, .1*inch))
story.append(Paragraph("<font color='darkblue'><b>e-mail : </b></font>" + "<user email id>", styleN))
story.append(Spacer(1, 1*inch))
# Create Table
tabledata = [[Paragraph('object',styleN),Paragraph('titletitletitletitletitletitletitletitletitletitletitle',styleN),Paragraph('description',styleN),Paragraph('latitude',styleN),Paragraph('longitude',styleN),Paragraph('mywlink',styleN)],
[Paragraph(str(x),styleB) for x in result1],[Paragraph(str(x),styleB) for x in result2],[Paragraph(str(x),styleB) for x in result3]]#,
colwidths = (80, 100, 100, 75, 75, 100)
GRID_STYLE = TableStyle(
[('GRID', (0,0), (-1,-1), 0.25, colors.black),
('ALIGN', (1,1), (-1,-1), 'LEFT'),
('TEXTCOLOR',(0,0), (-1,0), colors.darkblue)
]
)
t = Table(tabledata, colwidths, None, style=GRID_STYLE)
##t.setStyle(GRID_STYLE)
t.hAlign='LEFT'
story.append(t)
story.append(Spacer(1,.5*inch))
#build our document with the list of flowables we put together
doc = SimpleDocTemplate('myReport.pdf',pagesize = letter, leftMargin=0.5*inch, topMargin=0.3*inch)
doc.build(story)
この問題で私を助けてください。事前に感謝します