author | robin <robin@reportlab.com> |
Tue, 07 Mar 2017 10:00:34 +0000 | |
changeset 4330 | 617ffa6bbdc8 |
parent 4269 | 305766131a79 |
child 4341 | 19a971b1bfa4 |
permissions | -rw-r--r-- |
2963 | 1 |
#!/bin/env python |
4330 | 2 |
#Copyright ReportLab Europe Ltd. 2000-2017 |
2963 | 3 |
#see license.txt for license details |
4252 | 4 |
__version__='3.3.0' |
2963 | 5 |
__doc__='Test script for reportlab.tables' |
2987 | 6 |
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation |
2984 | 7 |
setOutDir(__name__) |
2966 | 8 |
import os,unittest |
3760
674899ebab37
platypus: FrameBG related stuff ifrom default that got lost somehow
robin
parents:
3721
diff
changeset
|
9 |
from reportlab.platypus import Spacer, SimpleDocTemplate, Table, TableStyle, FrameBG |
3148 | 10 |
from reportlab.platypus.paragraph import Paragraph |
11 |
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle |
|
2963 | 12 |
from reportlab.lib.units import inch, cm |
13 |
from reportlab.lib import colors |
|
3564
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
14 |
from reportlab.graphics.charts.linecharts import HorizontalLineChart |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
15 |
from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
16 |
from reportlab.graphics.charts.barcharts import VerticalBarChart |
2963 | 17 |
|
3148 | 18 |
styleSheet = getSampleStyleSheet() |
3760
674899ebab37
platypus: FrameBG related stuff ifrom default that got lost somehow
robin
parents:
3721
diff
changeset
|
19 |
|
2963 | 20 |
def getTable(): |
21 |
t = Table((('','North','South','East','West'), |
|
22 |
('Quarter 1',100,200,300,400), |
|
23 |
('Quarter 2',100,400,600,800), |
|
24 |
('Total',300,600,900,'1,200')), |
|
25 |
(72,36,36,36,36), |
|
26 |
(24, 16,16,18) |
|
27 |
) |
|
28 |
return t |
|
29 |
||
30 |
def makeStyles(): |
|
31 |
styles = [] |
|
32 |
for i in range(5): |
|
33 |
styles.append(TableStyle([('ALIGN', (1,1), (-1,-1), 'RIGHT'), |
|
34 |
('ALIGN', (0,0), (-1,0), 'CENTRE'), |
|
35 |
('HREF', (0,0), (0,0), 'www.google.com'), |
|
36 |
])) |
|
37 |
for style in styles[1:]: |
|
38 |
style.add('GRID', (0,0), (-1,-1), 0.25, colors.black) |
|
39 |
for style in styles[2:]: |
|
40 |
style.add('LINEBELOW', (0,0), (-1,0), 2, colors.black) |
|
41 |
for style in styles[3:]: |
|
42 |
style.add('LINEABOVE', (0, -1), (-1,-1), 2, colors.black) |
|
43 |
styles[-1].add('LINEBELOW',(1,-1), (-1, -1), 2, (0.5, 0.5, 0.5)) |
|
44 |
return styles |
|
45 |
||
46 |
def run(): |
|
47 |
doc = SimpleDocTemplate(outputfile('test_platypus_tables.pdf'), pagesize=(8.5*inch, 11*inch), showBoundary=1) |
|
3148 | 48 |
lst = [] |
3154 | 49 |
from reportlab import Version |
3148 | 50 |
styNormal = styleSheet['Normal'] |
3152 | 51 |
styBackground = ParagraphStyle('background', parent=styNormal, backColor=colors.pink) |
3148 | 52 |
styH1 = styleSheet['Heading1'] |
3760
674899ebab37
platypus: FrameBG related stuff ifrom default that got lost somehow
robin
parents:
3721
diff
changeset
|
53 |
lst.append(FrameBG(color=colors.red)) |
3148 | 54 |
lst.append(Paragraph("First, a test of how tables align their content...", styH1)) |
3154 | 55 |
lst.append(Paragraph("""Generated with version %s""" % Version, |
56 |
styNormal)) |
|
57 |
lst.append(Paragraph("""In release 2.3, cells with plain text positioned their |
|
3148 | 58 |
text differently to cells with Paragraphs using the |
3154 | 59 |
same font. Hopefully now they are back on the same baseline""", |
3148 | 60 |
styNormal)) |
3760
674899ebab37
platypus: FrameBG related stuff ifrom default that got lost somehow
robin
parents:
3721
diff
changeset
|
61 |
lst.append(FrameBG(color=colors.blue)) |
3148 | 62 |
ts1 = TableStyle([ |
63 |
('ALIGN', (0,0), (-1,0), 'RIGHT'), |
|
64 |
('BACKGROUND', (0,0), (-1,0), colors.lightgrey), |
|
65 |
('VALIGN', (0,0), (-1,-1), 'TOP'), |
|
66 |
('GRID', (0,0), (-1,-1), 0.25, colors.black), |
|
67 |
]) |
|
68 |
t1 = Table([ |
|
69 |
('plain text','plain text','shortpara','plain text', 'long para'), |
|
3154 | 70 |
('Text','more text', Paragraph('Is this para level?', styBackground), 'Back to text', Paragraph('Short para again', styBackground)), |
3152 | 71 |
('Text', |
72 |
'more text', |
|
3154 | 73 |
Paragraph('Is this level?', styBackground), |
3152 | 74 |
'This is plain\ntext with line breaks\nto compare against\nthe para on right', |
75 |
Paragraph('Long paragraph we expect to wrap over several lines accurately', styBackground)), |
|
4258
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
76 |
|
3148 | 77 |
]) |
78 |
t1.setStyle(ts1) |
|
79 |
lst.append(t1) |
|
3760
674899ebab37
platypus: FrameBG related stuff ifrom default that got lost somehow
robin
parents:
3721
diff
changeset
|
80 |
lst.append(FrameBG(start=False)) |
3148 | 81 |
lst.append(Spacer(0,10)) |
82 |
lst.append(Paragraph("Now we make a table with just one cell containing a string...note how the text sits low", styNormal)) |
|
3760
674899ebab37
platypus: FrameBG related stuff ifrom default that got lost somehow
robin
parents:
3721
diff
changeset
|
83 |
lst.append(FrameBG(start=False)) |
4258
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
84 |
|
3148 | 85 |
tsGrid = TableStyle([ |
86 |
('GRID', (0,0), (-1,-1), 0.25, colors.black), |
|
87 |
]) |
|
88 |
lst.append(Table([['One cell of plain text']], style=tsGrid, colWidths=[200])) |
|
4258
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
89 |
|
3148 | 90 |
lst.append(Spacer(0,10)) |
3154 | 91 |
lst.append(Paragraph("Now we make a table with just one cell containing a para...should be same position. Note that the overall bounding box is an approximation and lies - it always did.", styNormal)) |
3153 | 92 |
lst.append(Table([[Paragraph('One cell containing a paragraph. ÄÉ∫', styBackground)]], style=tsGrid, colWidths=[200])) |
3148 | 93 |
|
3149 | 94 |
lst.append(Spacer(0,10)) |
3148 | 95 |
lst.append(Paragraph("Paragraphs jumped up post 2.1. Ideally they should align the same.", styNormal)) |
4258
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
96 |
|
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
97 |
|
3149 | 98 |
lst.append(Spacer(0,30)) |
3148 | 99 |
lst.append(Paragraph("Now for all the tests we had before. See also the much longer test_platypus_tables_2.pdf, which for reasons unknown was split into a separate file generated by the same script", styNormal)) |
4258
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
100 |
|
2963 | 101 |
styles = makeStyles() |
102 |
for style in styles: |
|
103 |
t = getTable() |
|
104 |
t.setStyle(style) |
|
105 |
## print '--------------' |
|
106 |
## for rowstyle in t._cellstyles: |
|
107 |
## for s in rowstyle: |
|
108 |
## print s.alignment |
|
109 |
lst.append(t) |
|
110 |
lst.append(Spacer(0,12)) |
|
4258
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
111 |
|
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
112 |
t=Table([['VERTICAL Gradient Red top, grey bottom','Horizontal Gradient Blue left, green right'], |
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
113 |
['HORIZONTAL Gradient Span grey left red right', ''], |
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
114 |
['VERTICAL Gradiant Span Blue top green bottom',''], |
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
115 |
['','CLEAR']],[3.5*inch, 2.7*inch]) |
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
116 |
style=TableStyle([ |
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
117 |
('SPAN', (0,1),(1,1)), |
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
118 |
('SPAN', (0,2),(0,3)), |
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
119 |
('BACKGROUND',(0,0), (0,0),['VERTICAL', colors.grey, colors.red]), |
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
120 |
('BACKGROUND',(1,0), (1,0),['HORIZONTAL', colors.blue, colors.green]), |
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
121 |
('BACKGROUND',(0,1), (1,1),['HORIZONTAL', colors.grey, colors.red]), |
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
122 |
('BACKGROUND',(0,2), (0,3),['VERTICAL', colors.blue, colors.green]) |
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
123 |
]) |
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
124 |
t.setStyle(style) |
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
125 |
|
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
126 |
lst.append(t) |
2963 | 127 |
doc.build(lst) |
128 |
||
3564
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
129 |
class TableBarChart(_DrawingEditorMixin,Drawing): |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
130 |
def __init__(self,width=400,height=200,*args,**kw): |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
131 |
Drawing.__init__(self,width,height,*args,**kw) |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
132 |
self.width = 136 |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
133 |
self.height = 140 |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
134 |
self._add(self,VerticalBarChart(),name='chart',validate=None,desc=None) |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
135 |
self.chart.y = 20 |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
136 |
self.chart.width = self.width - 21 |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
137 |
self.chart.height = self.height - 24 |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
138 |
self.chart.categoryAxis.categoryNames = ['Spring','Summer','Autumn','Winter'] |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
139 |
self.chart.categoryAxis.labels.fontSize = 7 |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
140 |
|
2963 | 141 |
def old_tables_test(): |
142 |
from reportlab.lib.units import inch, cm |
|
143 |
from reportlab.platypus.flowables import Image, PageBreak, Spacer, XBox |
|
144 |
from reportlab.platypus.paragraph import Paragraph |
|
145 |
from reportlab.platypus.xpreformatted import XPreformatted |
|
146 |
from reportlab.platypus.flowables import Preformatted |
|
147 |
from reportlab.platypus.doctemplate import SimpleDocTemplate |
|
148 |
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle |
|
149 |
from reportlab.platypus.tables import GRID_STYLE, BOX_STYLE, LABELED_GRID_STYLE, COLORED_GRID_STYLE, LIST_STYLE, LongTable |
|
150 |
rowheights = (24, 16, 16, 16, 16) |
|
151 |
rowheights2 = (24, 16, 16, 16, 30) |
|
152 |
colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32) |
|
153 |
data = ( |
|
154 |
('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), |
|
155 |
('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), |
|
156 |
('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), |
|
157 |
('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), |
|
158 |
('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') |
|
159 |
) |
|
160 |
data2 = ( |
|
161 |
('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), |
|
162 |
('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), |
|
163 |
('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), |
|
164 |
('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), |
|
165 |
('Hats\nLarge', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') |
|
166 |
) |
|
167 |
lst = [] |
|
168 |
lst.append(Paragraph("Tables", styleSheet['Heading1'])) |
|
169 |
lst.append(Paragraph(__doc__, styleSheet['BodyText'])) |
|
170 |
lst.append(Paragraph("The Tables (shown in different styles below) were created using the following code:", styleSheet['BodyText'])) |
|
171 |
lst.append(Preformatted(""" |
|
172 |
colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32) |
|
173 |
rowheights = (24, 16, 16, 16, 16) |
|
174 |
data = ( |
|
175 |
('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', |
|
176 |
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), |
|
177 |
('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), |
|
178 |
('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), |
|
179 |
('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), |
|
180 |
('Hats', 893, 912, '1,212', 643, 789, 159, |
|
181 |
888, '1,298', 832, 453, '1,344','2,843') |
|
182 |
) |
|
183 |
t = Table(data, colwidths, rowheights) |
|
184 |
""", styleSheet['Code'], dedent=4)) |
|
185 |
lst.append(Paragraph(""" |
|
186 |
You can then give the Table a TableStyle object to control its format. The first TableStyle used was |
|
187 |
created as follows: |
|
188 |
""", styleSheet['BodyText'])) |
|
189 |
lst.append(Preformatted(""" |
|
190 |
GRID_STYLE = TableStyle( |
|
191 |
[('GRID', (0,0), (-1,-1), 0.25, colors.black), |
|
192 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
193 |
) |
|
194 |
""", styleSheet['Code'])) |
|
195 |
lst.append(Paragraph(""" |
|
196 |
TableStyles are created by passing in a list of commands. There are two types of commands - line commands |
|
197 |
and cell formatting commands. In all cases, the first three elements of a command are the command name, |
|
198 |
the starting cell and the ending cell. |
|
199 |
""", styleSheet['BodyText'])) |
|
200 |
lst.append(Paragraph(""" |
|
201 |
Line commands always follow this with the weight and color of the desired lines. Colors can be names, |
|
202 |
or they can be specified as a (R,G,B) tuple, where R, G and B are floats and (0,0,0) is black. The line |
|
203 |
command names are: GRID, BOX, OUTLINE, INNERGRID, LINEBELOW, LINEABOVE, LINEBEFORE |
|
204 |
and LINEAFTER. BOX and OUTLINE are equivalent, and GRID is the equivalent of applying both BOX and |
|
205 |
INNERGRID. |
|
206 |
""", styleSheet['BodyText'])) |
|
207 |
lst.append(Paragraph(""" |
|
208 |
Cell formatting commands are: |
|
209 |
""", styleSheet['BodyText'])) |
|
210 |
lst.append(Paragraph(""" |
|
211 |
FONT - takes fontname, fontsize and (optional) leading. |
|
212 |
""", styleSheet['Definition'])) |
|
213 |
lst.append(Paragraph(""" |
|
214 |
TEXTCOLOR - takes a color name or (R,G,B) tuple. |
|
215 |
""", styleSheet['Definition'])) |
|
216 |
lst.append(Paragraph(""" |
|
217 |
ALIGNMENT (or ALIGN) - takes one of LEFT, RIGHT, CENTRE (or CENTER) or DECIMAL. |
|
218 |
""", styleSheet['Definition'])) |
|
219 |
lst.append(Paragraph(""" |
|
220 |
LEFTPADDING - defaults to 6. |
|
221 |
""", styleSheet['Definition'])) |
|
222 |
lst.append(Paragraph(""" |
|
223 |
RIGHTPADDING - defaults to 6. |
|
224 |
""", styleSheet['Definition'])) |
|
225 |
lst.append(Paragraph(""" |
|
226 |
BOTTOMPADDING - defaults to 3. |
|
227 |
""", styleSheet['Definition'])) |
|
228 |
lst.append(Paragraph(""" |
|
229 |
A tablestyle is applied to a table by calling Table.setStyle(tablestyle). |
|
230 |
""", styleSheet['BodyText'])) |
|
231 |
t = Table(data, colwidths, rowheights) |
|
232 |
t.setStyle(GRID_STYLE) |
|
233 |
lst.append(PageBreak()) |
|
234 |
lst.append(Paragraph("This is GRID_STYLE\n", styleSheet['BodyText'])) |
|
235 |
lst.append(t) |
|
236 |
||
237 |
t = Table(data, colwidths, rowheights) |
|
238 |
t.setStyle(BOX_STYLE) |
|
239 |
lst.append(Paragraph("This is BOX_STYLE\n", styleSheet['BodyText'])) |
|
240 |
lst.append(t) |
|
241 |
lst.append(Paragraph(""" |
|
242 |
It was created as follows: |
|
243 |
""", styleSheet['BodyText'])) |
|
244 |
lst.append(Preformatted(""" |
|
245 |
BOX_STYLE = TableStyle( |
|
246 |
[('BOX', (0,0), (-1,-1), 0.50, colors.black), |
|
247 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
248 |
) |
|
249 |
""", styleSheet['Code'])) |
|
250 |
||
251 |
t = Table(data, colwidths, rowheights) |
|
252 |
t.setStyle(LABELED_GRID_STYLE) |
|
253 |
lst.append(Paragraph("This is LABELED_GRID_STYLE\n", styleSheet['BodyText'])) |
|
254 |
lst.append(t) |
|
255 |
t = Table(data2, colwidths, rowheights2) |
|
256 |
t.setStyle(LABELED_GRID_STYLE) |
|
257 |
lst.append(Paragraph("This is LABELED_GRID_STYLE ILLUSTRATES EXPLICIT LINE SPLITTING WITH NEWLINE (different heights and data)\n", styleSheet['BodyText'])) |
|
258 |
lst.append(t) |
|
259 |
lst.append(Paragraph(""" |
|
260 |
It was created as follows: |
|
261 |
""", styleSheet['BodyText'])) |
|
262 |
lst.append(Preformatted(""" |
|
263 |
LABELED_GRID_STYLE = TableStyle( |
|
264 |
[('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
|
265 |
('BOX', (0,0), (-1,-1), 2, colors.black), |
|
266 |
('LINEBELOW', (0,0), (-1,0), 2, colors.black), |
|
267 |
('LINEAFTER', (0,0), (0,-1), 2, colors.black), |
|
268 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
269 |
) |
|
270 |
""", styleSheet['Code'])) |
|
271 |
lst.append(PageBreak()) |
|
272 |
||
273 |
t = Table(data, colwidths, rowheights) |
|
274 |
t.setStyle(COLORED_GRID_STYLE) |
|
275 |
lst.append(Paragraph("This is COLORED_GRID_STYLE\n", styleSheet['BodyText'])) |
|
276 |
lst.append(t) |
|
277 |
lst.append(Paragraph(""" |
|
278 |
It was created as follows: |
|
279 |
""", styleSheet['BodyText'])) |
|
280 |
lst.append(Preformatted(""" |
|
281 |
COLORED_GRID_STYLE = TableStyle( |
|
282 |
[('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
|
283 |
('BOX', (0,0), (-1,-1), 2, colors.red), |
|
284 |
('LINEBELOW', (0,0), (-1,0), 2, colors.black), |
|
285 |
('LINEAFTER', (0,0), (0,-1), 2, colors.black), |
|
286 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
287 |
) |
|
288 |
""", styleSheet['Code'])) |
|
289 |
||
290 |
t = Table(data, colwidths, rowheights) |
|
291 |
t.setStyle(LIST_STYLE) |
|
292 |
lst.append(Paragraph("This is LIST_STYLE\n", styleSheet['BodyText'])) |
|
293 |
lst.append(t) |
|
294 |
lst.append(Paragraph(""" |
|
295 |
It was created as follows: |
|
296 |
""", styleSheet['BodyText'])) |
|
297 |
lst.append(Preformatted(""" |
|
298 |
LIST_STYLE = TableStyle( |
|
299 |
[('LINEABOVE', (0,0), (-1,0), 2, colors.green), |
|
300 |
('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black), |
|
301 |
('LINEBELOW', (0,-1), (-1,-1), 2, colors.green), |
|
302 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
303 |
) |
|
304 |
""", styleSheet['Code'])) |
|
305 |
||
306 |
t = Table(data, colwidths, rowheights) |
|
307 |
ts = TableStyle( |
|
308 |
[('LINEABOVE', (0,0), (-1,0), 2, colors.green), |
|
309 |
('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black), |
|
310 |
('LINEBELOW', (0,-1), (-1,-1), 3, colors.green,'butt'), |
|
311 |
('LINEBELOW', (0,-1), (-1,-1), 1, colors.white,'butt'), |
|
312 |
('ALIGN', (1,1), (-1,-1), 'RIGHT'), |
|
313 |
('TEXTCOLOR', (0,1), (0,-1), colors.red), |
|
314 |
('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))] |
|
315 |
) |
|
316 |
t.setStyle(ts) |
|
317 |
lst.append(Paragraph("This is a custom style\n", styleSheet['BodyText'])) |
|
318 |
lst.append(t) |
|
319 |
lst.append(Paragraph(""" |
|
320 |
It was created as follows: |
|
321 |
""", styleSheet['BodyText'])) |
|
322 |
lst.append(Preformatted(""" |
|
323 |
ts = TableStyle( |
|
324 |
[('LINEABOVE', (0,0), (-1,0), 2, colors.green), |
|
325 |
('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black), |
|
326 |
('LINEBELOW', (0,-1), (-1,-1), 3, colors.green,'butt'), |
|
327 |
('LINEBELOW', (0,-1), (-1,-1), 1, colors.white,'butt'), |
|
328 |
('ALIGN', (1,1), (-1,-1), 'RIGHT'), |
|
329 |
('TEXTCOLOR', (0,1), (0,-1), colors.red), |
|
330 |
('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))] |
|
331 |
) |
|
332 |
""", styleSheet['Code'])) |
|
333 |
data = ( |
|
334 |
('', 'Jan\nCold', 'Feb\n', 'Mar\n','Apr\n','May\n', 'Jun\nHot', 'Jul\n', 'Aug\nThunder', 'Sep\n', 'Oct\n', 'Nov\n', 'Dec\n'), |
|
335 |
('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), |
|
336 |
('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), |
|
337 |
('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), |
|
338 |
('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') |
|
339 |
) |
|
340 |
c = list(colwidths) |
|
341 |
c[0] = None |
|
342 |
c[8] = None |
|
343 |
t = Table(data, c, [None]+list(rowheights[1:])) |
|
344 |
t.setStyle(LIST_STYLE) |
|
345 |
lst.append(Paragraph(""" |
|
346 |
This is a LIST_STYLE table with the first rowheight set to None ie automatic. |
|
347 |
The top row cells are split at a newline '\\n' character. The first and August |
|
348 |
column widths were also set to None. |
|
349 |
""", styleSheet['BodyText'])) |
|
350 |
lst.append(t) |
|
351 |
||
352 |
lst.append(Paragraph(""" |
|
353 |
This demonstrates a number of features useful in financial statements. The first is decimal alignment; |
|
354 |
with ALIGN=DECIMAL the numbers align on the points; and the points are aligned based on |
|
355 |
the RIGHTPADDING, which is usually 3 points so you should set it higher. The second is multiple lines; |
|
356 |
one can specify double or triple lines and control the separation if desired. Finally, the coloured |
|
357 |
negative numbers were (we regret to say) done in the style; we don't have a way to conditionally |
|
358 |
format numbers based on value yet. |
|
359 |
""", styleSheet['BodyText'])) |
|
360 |
||
361 |
||
3721 | 362 |
t = Table([['Corporate Assets','Amount'], |
2963 | 363 |
['Fixed Assets','1,234,567.89'], |
364 |
['Company Vehicle','1,234.8901'], |
|
365 |
['Petty Cash','42'], |
|
3721 | 366 |
['Intellectual Property\u00ae','(42,078,231.56)'], |
2963 | 367 |
['Overdraft','(12,345)'], |
368 |
['Boardroom Flat Screen','60 inches'], |
|
369 |
['Net Position','Deep Sh*t.Really'] |
|
370 |
], |
|
371 |
[144,72]) |
|
372 |
||
373 |
ts = TableStyle( |
|
374 |
[#first the top row |
|
375 |
('ALIGN', (1,1), (-1,-1), 'CENTER'), |
|
376 |
('LINEABOVE', (0,0), (-1,0), 1, colors.purple), |
|
377 |
('LINEBELOW', (0,0), (-1,0), 1, colors.purple), |
|
378 |
('FONT', (0,0), (-1,0), 'Times-Bold'), |
|
379 |
||
380 |
#bottom row has a line above, and two lines below |
|
381 |
('LINEABOVE', (0,-1), (-1,-1), 1, colors.purple), #last 2 are count, sep |
|
382 |
('LINEBELOW', (0,-1), (-1,-1), 0.5, colors.purple, 1, None, None, 4,1), |
|
383 |
('LINEBELOW', (0,-1), (-1,-1), 1, colors.red), |
|
384 |
('FONT', (0,-1), (-1,-1), 'Times-Bold'), |
|
385 |
||
386 |
#numbers column |
|
387 |
('ALIGN', (1,1), (-1,-1), 'DECIMAL'), |
|
388 |
('RIGHTPADDING', (1,1), (-1,-1), 36), |
|
389 |
('TEXTCOLOR', (1,4), (1,4), colors.red), |
|
390 |
||
4258
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
391 |
#red cell |
2963 | 392 |
] |
393 |
) |
|
394 |
||
395 |
t.setStyle(ts) |
|
396 |
lst.append(t) |
|
4258
d3e9de82a5aa
add table cell support for simple background shadings, contributed by Jeffrey Creem jcreem@bitbucket
robin
parents:
4252
diff
changeset
|
397 |
lst.append(Spacer(36,36)) |
2963 | 398 |
lst.append(Paragraph(""" |
399 |
The red numbers should be aligned LEFT & BOTTOM, the blue RIGHT & TOP |
|
400 |
and the green CENTER & MIDDLE. |
|
401 |
""", styleSheet['BodyText'])) |
|
402 |
XY = [['X00y', 'X01y', 'X02y', 'X03y', 'X04y'], |
|
403 |
['X10y', 'X11y', 'X12y', 'X13y', 'X14y'], |
|
404 |
['X20y', 'X21y', 'X22y', 'X23y', 'X24y'], |
|
405 |
['X30y', 'X31y', 'X32y', 'X33y', 'X34y']] |
|
406 |
t=Table(XY, 5*[0.6*inch], 4*[0.6*inch]) |
|
407 |
t.setStyle([('ALIGN',(1,1),(-2,-2),'LEFT'), |
|
408 |
('TEXTCOLOR',(1,1),(-2,-2),colors.red), |
|
409 |
||
410 |
('VALIGN',(0,0),(1,-1),'TOP'), |
|
411 |
('ALIGN',(0,0),(1,-1),'RIGHT'), |
|
412 |
('TEXTCOLOR',(0,0),(1,-1),colors.blue), |
|
413 |
||
414 |
('ALIGN',(0,-1),(-1,-1),'CENTER'), |
|
415 |
('VALIGN',(0,-1),(-1,-1),'MIDDLE'), |
|
416 |
('TEXTCOLOR',(0,-1),(-1,-1),colors.green), |
|
417 |
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
|
418 |
('BOX', (0,0), (-1,-1), 0.25, colors.black), |
|
419 |
]) |
|
420 |
lst.append(t) |
|
421 |
data = [('alignment', 'align\012alignment'), |
|
422 |
('bulletColor', 'bulletcolor\012bcolor'), |
|
423 |
('bulletFontName', 'bfont\012bulletfontname'), |
|
424 |
('bulletFontSize', 'bfontsize\012bulletfontsize'), |
|
425 |
('bulletIndent', 'bindent\012bulletindent'), |
|
426 |
('firstLineIndent', 'findent\012firstlineindent'), |
|
427 |
('fontName', 'face\012fontname\012font'), |
|
428 |
('fontSize', 'size\012fontsize'), |
|
429 |
('leading', 'leading'), |
|
430 |
('leftIndent', 'leftindent\012lindent'), |
|
431 |
('rightIndent', 'rightindent\012rindent'), |
|
432 |
('spaceAfter', 'spaceafter\012spacea'), |
|
433 |
('spaceBefore', 'spacebefore\012spaceb'), |
|
434 |
('textColor', 'fg\012textcolor\012color')] |
|
435 |
t = Table(data) |
|
436 |
t.setStyle([ |
|
437 |
('VALIGN',(0,0),(-1,-1),'TOP'), |
|
438 |
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
|
439 |
('BOX', (0,0), (-1,-1), 0.25, colors.black), |
|
440 |
]) |
|
441 |
lst.append(t) |
|
442 |
t = Table([ ('Attribute', 'Synonyms'), |
|
443 |
('alignment', 'align, alignment'), |
|
444 |
('bulletColor', 'bulletcolor, bcolor'), |
|
445 |
('bulletFontName', 'bfont, bulletfontname'), |
|
446 |
('bulletFontSize', 'bfontsize, bulletfontsize'), |
|
447 |
('bulletIndent', 'bindent, bulletindent'), |
|
448 |
('firstLineIndent', 'findent, firstlineindent'), |
|
449 |
('fontName', 'face, fontname, font'), |
|
450 |
('fontSize', 'size, fontsize'), |
|
451 |
('leading', 'leading'), |
|
452 |
('leftIndent', 'leftindent, lindent'), |
|
453 |
('rightIndent', 'rightindent, rindent'), |
|
454 |
('spaceAfter', 'spaceafter, spacea'), |
|
455 |
('spaceBefore', 'spacebefore, spaceb'), |
|
456 |
('textColor', 'fg, textcolor, color')]) |
|
457 |
t.repeatRows = 1 |
|
458 |
t.setStyle([ |
|
459 |
('FONT',(0,0),(-1,1),'Times-Bold',10,12), |
|
460 |
('FONT',(0,1),(-1,-1),'Courier',8,8), |
|
461 |
('VALIGN',(0,0),(-1,-1),'MIDDLE'), |
|
462 |
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
|
463 |
('BOX', (0,0), (-1,-1), 0.25, colors.black), |
|
464 |
('BACKGROUND', (0, 0), (-1, 0), colors.green), |
|
465 |
('BACKGROUND', (0, 1), (-1, -1), colors.pink), |
|
466 |
('ALIGN', (0, 0), (-1, 0), 'CENTER'), |
|
467 |
('ALIGN', (0, 1), (0, -1), 'LEFT'), |
|
468 |
('ALIGN', (-1, 1), (-1, -1), 'RIGHT'), |
|
469 |
('FONT', (0, 0), (-1, 0), 'Times-Bold', 12), |
|
470 |
('ALIGN', (1, 1), (1, -1), 'CENTER'), |
|
471 |
]) |
|
472 |
lst.append(t) |
|
473 |
lst.append(Table(XY, |
|
474 |
style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 5,6), |
|
475 |
('GRID', (0,0), (-1,-1), 0.25, colors.blue),])) |
|
476 |
lst.append(Table(XY, |
|
477 |
style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 10,12), |
|
478 |
('GRID', (0,0), (-1,-1), 0.25, colors.black),])) |
|
479 |
lst.append(Table(XY, |
|
480 |
style=[ ('FONT',(0,0),(-1,-1),'Times-Roman', 20,24), |
|
481 |
('GRID', (0,0), (-1,-1), 0.25, colors.red),])) |
|
482 |
lst.append(PageBreak()) |
|
483 |
data= [['00', '01', '02', '03', '04'], |
|
484 |
['10', '11', '12', '13', '14'], |
|
485 |
['20', '21', '22', '23', '24'], |
|
486 |
['30', '31', '32', '33', '34']] |
|
487 |
t=Table(data,style=[ |
|
488 |
('GRID',(0,0),(-1,-1),0.5,colors.grey), |
|
489 |
('GRID',(1,1),(-2,-2),1,colors.green), |
|
490 |
('BOX',(0,0),(1,-1),2,colors.red), |
|
491 |
('BOX',(0,0),(-1,-1),2,colors.black), |
|
492 |
('LINEABOVE',(1,2),(-2,2),1,colors.blue), |
|
493 |
('LINEBEFORE',(2,1),(2,-2),1,colors.pink), |
|
494 |
('BACKGROUND', (0, 0), (0, 1), colors.pink), |
|
495 |
('BACKGROUND', (1, 1), (1, 2), colors.lavender), |
|
496 |
('BACKGROUND', (2, 2), (2, 3), colors.orange), |
|
4269
305766131a79
add negative span style to test_platypus_tables splitting example
robin
parents:
4264
diff
changeset
|
497 |
('TEXTCOLOR',(0,-1),(-2,-1),colors.green), |
2963 | 498 |
]) |
499 |
lst.append(Paragraph("Illustrating splits: nosplit", styleSheet['BodyText'])) |
|
500 |
lst.append(t) |
|
501 |
lst.append(Spacer(0,6)) |
|
502 |
lst.append(Paragraph("Illustrating splits: split(4in,30)", styleSheet['BodyText'])) |
|
503 |
for s in t.split(4*inch,30): |
|
504 |
lst.append(s) |
|
505 |
lst.append(Spacer(0,6)) |
|
506 |
lst.append(Spacer(0,6)) |
|
507 |
lst.append(Paragraph("Illustrating splits: split(4in,36)", styleSheet['BodyText'])) |
|
508 |
for s in t.split(4*inch,36): |
|
509 |
lst.append(s) |
|
510 |
lst.append(Spacer(0,6)) |
|
511 |
lst.append(Paragraph("Illustrating splits: split(4in,56)", styleSheet['BodyText'])) |
|
512 |
lst.append(Spacer(0,6)) |
|
513 |
for s in t.split(4*inch,56): |
|
514 |
lst.append(s) |
|
515 |
lst.append(Spacer(0,6)) |
|
516 |
||
4269
305766131a79
add negative span style to test_platypus_tables splitting example
robin
parents:
4264
diff
changeset
|
517 |
lst.append(Paragraph("Illustrating splits: repeated split(4in,30)", styleSheet['BodyText'])) |
305766131a79
add negative span style to test_platypus_tables splitting example
robin
parents:
4264
diff
changeset
|
518 |
lst.append(Spacer(0,6)) |
305766131a79
add negative span style to test_platypus_tables splitting example
robin
parents:
4264
diff
changeset
|
519 |
S = t.split(4*inch,30) |
305766131a79
add negative span style to test_platypus_tables splitting example
robin
parents:
4264
diff
changeset
|
520 |
s = S.pop(-1) |
305766131a79
add negative span style to test_platypus_tables splitting example
robin
parents:
4264
diff
changeset
|
521 |
S.extend(s.split(4*inch,30)) |
305766131a79
add negative span style to test_platypus_tables splitting example
robin
parents:
4264
diff
changeset
|
522 |
s = S.pop(-1) |
305766131a79
add negative span style to test_platypus_tables splitting example
robin
parents:
4264
diff
changeset
|
523 |
S.extend(s.split(4*inch,30)) |
305766131a79
add negative span style to test_platypus_tables splitting example
robin
parents:
4264
diff
changeset
|
524 |
|
305766131a79
add negative span style to test_platypus_tables splitting example
robin
parents:
4264
diff
changeset
|
525 |
for s in S: |
305766131a79
add negative span style to test_platypus_tables splitting example
robin
parents:
4264
diff
changeset
|
526 |
lst.append(s) |
305766131a79
add negative span style to test_platypus_tables splitting example
robin
parents:
4264
diff
changeset
|
527 |
lst.append(Spacer(0,6)) |
305766131a79
add negative span style to test_platypus_tables splitting example
robin
parents:
4264
diff
changeset
|
528 |
|
2963 | 529 |
lst.append(PageBreak()) |
530 |
data= [['00', '01', '02', '03', '04'], |
|
531 |
['', '11', '12', '13', '14'], |
|
532 |
['20', '21', '22', '23', '24'], |
|
533 |
['30', '31', '', '33', '34']] |
|
534 |
sty=[ |
|
535 |
('GRID',(0,0),(-1,-1),0.5,colors.grey), |
|
536 |
('GRID',(1,1),(-2,-2),1,colors.green), |
|
537 |
('BOX',(0,0),(1,-1),2,colors.red), |
|
538 |
('BOX',(0,0),(-1,-1),2,colors.black), |
|
539 |
('LINEABOVE',(1,2),(-2,2),1,colors.blue), |
|
540 |
('LINEBEFORE',(2,1),(2,-2),1,colors.pink), |
|
541 |
('BACKGROUND', (0, 0), (0, 1), colors.pink), |
|
542 |
('SPAN',(0,0),(0,1)), |
|
543 |
('BACKGROUND', (2, 2), (2, 3), colors.orange), |
|
544 |
('SPAN',(2,2),(2,3)), |
|
545 |
] |
|
546 |
t=Table(data,style=sty) |
|
547 |
lst.append(Paragraph("Illustrating splits with spans: nosplit", styleSheet['BodyText'])) |
|
548 |
lst.append(t) |
|
549 |
lst.append(Spacer(0,6)) |
|
550 |
lst.append(Paragraph("Illustrating splits with spans: split(4in,30)", styleSheet['BodyText'])) |
|
551 |
for s in t.split(4*inch,30): |
|
552 |
lst.append(s) |
|
553 |
lst.append(Spacer(0,6)) |
|
554 |
lst.append(Spacer(0,6)) |
|
555 |
lst.append(Paragraph("Illustrating splits with spans: split(4in,36)", styleSheet['BodyText'])) |
|
556 |
for s in t.split(4*inch,36): |
|
557 |
lst.append(s) |
|
558 |
lst.append(Spacer(0,6)) |
|
559 |
lst.append(Paragraph("Illustrating splits with spans: split(4in,56)", styleSheet['BodyText'])) |
|
560 |
lst.append(Spacer(0,6)) |
|
561 |
for s in t.split(4*inch,56): |
|
562 |
lst.append(s) |
|
563 |
lst.append(Spacer(0,6)) |
|
564 |
||
565 |
data= [['00', '01', '02', '03', '04'], |
|
566 |
['', '11', '12', '13', ''], |
|
567 |
['20', '21', '22', '23', '24'], |
|
568 |
['30', '31', '', '33', ''], |
|
569 |
['40', '41', '', '43', '44']] |
|
570 |
sty=[ |
|
571 |
('GRID',(0,0),(-1,-1),0.5,colors.grey), |
|
572 |
('GRID',(1,1),(-2,-2),1,colors.green), |
|
573 |
('BOX',(0,0),(1,-1),2,colors.red), |
|
574 |
('BOX',(0,0),(-1,-1),2,colors.black), |
|
575 |
('LINEABOVE',(1,2),(-2,2),1,colors.blue), |
|
576 |
('LINEBEFORE',(2,1),(2,-2),1,colors.pink), |
|
577 |
('BACKGROUND', (0, 0), (0, 1), colors.pink), |
|
578 |
('SPAN',(0,0),(0,1)), |
|
579 |
('BACKGROUND',(-2,1),(-1,1),colors.palegreen), |
|
580 |
('SPAN',(-2,1),(-1,1)), |
|
581 |
('BACKGROUND',(-2,3),(-1,3),colors.yellow), |
|
582 |
('SPAN',(-2,3),(-1,3)), |
|
583 |
('BACKGROUND', (2, 3), (2, 4), colors.orange), |
|
584 |
('SPAN',(2,3),(2,4)), |
|
585 |
] |
|
586 |
||
587 |
t=Table(data,style=sty,repeatRows=2) |
|
588 |
lst.append(Paragraph("Illustrating splits with spans and repeatRows: nosplit", styleSheet['BodyText'])) |
|
589 |
lst.append(t) |
|
590 |
lst.append(Spacer(0,6)) |
|
3461 | 591 |
if 1: |
2963 | 592 |
lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,30)", styleSheet['BodyText'])) |
593 |
for s in t.split(4*inch,30): |
|
594 |
lst.append(s) |
|
595 |
lst.append(Spacer(0,6)) |
|
596 |
lst.append(Spacer(0,6)) |
|
597 |
lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,36)", styleSheet['BodyText'])) |
|
598 |
for s in t.split(4*inch,36): |
|
599 |
lst.append(s) |
|
600 |
lst.append(Spacer(0,6)) |
|
601 |
lst.append(Paragraph("Illustrating splits with spans and repeatRows: split(4in,56)", styleSheet['BodyText'])) |
|
602 |
lst.append(Spacer(0,6)) |
|
603 |
for s in t.split(4*inch,56): |
|
604 |
lst.append(s) |
|
605 |
lst.append(Spacer(0,6)) |
|
606 |
||
607 |
lst.append(PageBreak()) |
|
2987 | 608 |
from reportlab.lib.testutils import testsFolder |
2966 | 609 |
I = Image(os.path.join(os.path.dirname(testsFolder),'tools','pythonpoint','demos','leftlogo.gif')) |
2963 | 610 |
I.drawHeight = 1.25*inch*I.drawHeight / I.drawWidth |
611 |
I.drawWidth = 1.25*inch |
|
612 |
#I.drawWidth = 9.25*inch #uncomment to see better messaging |
|
613 |
P = Paragraph("<para align=center spaceb=3>The <b>ReportLab Left <font color=red>Logo</font></b> Image</para>", styleSheet["BodyText"]) |
|
3564
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
614 |
B = TableBarChart() |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
615 |
BP = Paragraph("<para align=center spaceb=3>A bar chart in a cell.</para>", styleSheet["BodyText"]) |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
616 |
|
2963 | 617 |
data= [['A', 'B', 'C', Paragraph("<b>A pa<font color=red>r</font>a<i>graph</i></b><super><font color=yellow>1</font></super>",styleSheet["BodyText"]), 'D'], |
618 |
['00', '01', '02', [I,P], '04'], |
|
619 |
['10', '11', '12', [I,P], '14'], |
|
620 |
['20', '21', '22', '23', '24'], |
|
3564
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
621 |
['30', '31', '32', '33', '34'], |
fd1f9e74eac2
test_platypus_paragraphs.py simple test of PageTemplate.autoNextPageTemplate
rgbecker
parents:
3461
diff
changeset
|
622 |
['40', '41', '42', [B,BP], '44']] |
2963 | 623 |
|
624 |
t=Table(data,style=[('GRID',(1,1),(-2,-2),1,colors.green), |
|
625 |
('BOX',(0,0),(1,-1),2,colors.red), |
|
626 |
('LINEABOVE',(1,2),(-2,2),1,colors.blue), |
|
627 |
('LINEBEFORE',(2,1),(2,-2),1,colors.pink), |
|
628 |
('BACKGROUND', (0, 0), (0, 1), colors.pink), |
|
629 |
('BACKGROUND', (1, 1), (1, 2), colors.lavender), |
|
630 |
('BACKGROUND', (2, 2), (2, 3), colors.orange), |
|
631 |
('BOX',(0,0),(-1,-1),2,colors.black), |
|
632 |
('GRID',(0,0),(-1,-1),0.5,colors.black), |
|
633 |
('VALIGN',(3,0),(3,0),'BOTTOM'), |
|
634 |
('BACKGROUND',(3,0),(3,0),colors.limegreen), |
|
635 |
('BACKGROUND',(3,1),(3,1),colors.khaki), |
|
636 |
('ALIGN',(3,1),(3,1),'CENTER'), |
|
637 |
('BACKGROUND',(3,2),(3,2),colors.beige), |
|
638 |
('ALIGN',(3,2),(3,2),'LEFT'), |
|
639 |
]) |
|
640 |
||
641 |
t._argW[3]=1.5*inch |
|
642 |
lst.append(t) |
|
643 |
||
644 |
# now for an attempt at column spanning. |
|
645 |
lst.append(PageBreak()) |
|
646 |
data= [['A', 'BBBBB', 'C', 'D', 'E'], |
|
647 |
['00', '01', '02', '03', '04'], |
|
648 |
['10', '11', '12', '13', '14'], |
|
649 |
['20', '21', '22', '23', '24'], |
|
650 |
['30', '31', '32', '33', '34']] |
|
651 |
sty = [ |
|
652 |
('ALIGN',(0,0),(-1,-1),'CENTER'), |
|
653 |
('VALIGN',(0,0),(-1,-1),'TOP'), |
|
654 |
('GRID',(0,0),(-1,-1),1,colors.green), |
|
655 |
('BOX',(0,0),(-1,-1),2,colors.red), |
|
656 |
||
657 |
#span 'BBBB' across middle 3 cells in top row |
|
658 |
('SPAN',(1,0),(3,0)), |
|
659 |
#now color the first cell in this range only, |
|
660 |
#i.e. the one we want to have spanned. Hopefuly |
|
661 |
#the range of 3 will come out khaki. |
|
662 |
('BACKGROUND',(1,0),(1,0),colors.khaki), |
|
663 |
||
664 |
('SPAN',(0,2),(-1,2)), |
|
665 |
||
666 |
||
667 |
#span 'AAA'down entire left column |
|
668 |
('SPAN',(0,0), (0, 1)), |
|
669 |
('BACKGROUND',(0,0),(0,0),colors.cyan), |
|
670 |
('LINEBELOW', (0,'splitlast'), (-1,'splitlast'), 1, colors.white,'butt'), |
|
671 |
] |
|
672 |
t=Table(data,style=sty, colWidths = [20] * 5, rowHeights = [20]*5) |
|
673 |
lst.append(t) |
|
674 |
||
675 |
# now for an attempt at percentage widths |
|
676 |
lst.append(Spacer(18,18)) |
|
677 |
lst.append(Paragraph("This table has colWidths=5*['14%']!", styleSheet['BodyText'])) |
|
678 |
t=Table(data,style=sty, colWidths = ['14%'] * 5, rowHeights = [20]*5) |
|
679 |
lst.append(t) |
|
680 |
||
681 |
lst.append(Spacer(18,18)) |
|
682 |
lst.append(Paragraph("This table has colWidths=['14%','10%','19%','22%','*']!", styleSheet['BodyText'])) |
|
683 |
t=Table(data,style=sty, colWidths = ['14%','10%','19%','22%','*'], rowHeights = [20]*5) |
|
684 |
lst.append(t) |
|
685 |
||
686 |
# Mike's test example |
|
687 |
lst.append(Spacer(18,18)) |
|
688 |
lst.append(Paragraph('Mike\'s Spanning Example', styleSheet['Heading1'])) |
|
689 |
data= [[Paragraph('World Domination: The First Five Years', styleSheet['BodyText']), ''], |
|
690 |
[Paragraph('World <font color="green">Domination</font>: The First Five Years', styleSheet['BodyText']),''], |
|
691 |
[Paragraph('World Domination: The First Five Years', styleSheet['BodyText']), ''], |
|
692 |
] |
|
693 |
t=Table(data, style=[('SPAN',(0,0),(1,0)),('SPAN',(0,1),(1,1)),('SPAN',(0,2),(1,2)),], colWidths = [3*cm,8*cm], rowHeights = [None]*3) |
|
694 |
lst.append(t) |
|
695 |
||
696 |
lst.append(Spacer(18,18)) |
|
697 |
lst.append(Paragraph('Mike\'s Non-spanning Example', styleSheet['Heading1'])) |
|
698 |
data= [[Paragraph('World Domination: The First Five Years', styleSheet['BodyText'])], |
|
699 |
[Paragraph('World <font color="magenta">Domination</font>: The First Five Years', styleSheet['BodyText'])], |
|
700 |
[Paragraph('World Domination: The First Five Years', styleSheet['BodyText'])], |
|
701 |
] |
|
702 |
t=Table(data, style=[], colWidths = [11*cm], rowHeights = [None]*3) |
|
703 |
lst.append(t) |
|
704 |
||
705 |
lst.append(Spacer(18,18)) |
|
706 |
lst.append(Paragraph('xpre example', styleSheet['Heading1'])) |
|
707 |
data= [ [ |
|
708 |
XPreformatted('Account Details', styleSheet['Heading3']), |
|
709 |
'', XPreformatted('Client Details', styleSheet['Heading3']), |
|
710 |
], #end of row 0 |
|
711 |
] |
|
712 |
t=Table(data, style=[], colWidths = [80,230.0,80], rowHeights = [None]*1) |
|
713 |
lst.append(t) |
|
714 |
||
715 |
lst.append(PageBreak()) |
|
716 |
||
717 |
lst.append(Paragraph('Trying colour cycling in background', styleSheet['Heading1'])) |
|
718 |
lst.append(Paragraph("This should alternate pale blue and uncolored by row", styleSheet['BodyText'])) |
|
719 |
data= [['001', '01', '02', '03', '04', '05'], |
|
720 |
['002', '01', '02', '03', '04', '05'], |
|
721 |
['003', '01', '02', '03', '04', '05'], |
|
722 |
['004', '01', '02', '03', '04', '05'], |
|
723 |
['005', '01', '02', '03', '04', '05'], |
|
724 |
['006', '01', '02', '03', '04', '05'], |
|
725 |
['007', '01', '02', '03', '04', '05'], |
|
726 |
['008', '01', '02', '03', '04', '05'], |
|
727 |
['009', '01', '02', '03', '04', '05'], |
|
728 |
['010', '01', '02', '03', '04', '05'], |
|
729 |
||
730 |
] |
|
731 |
t=Table(data,style=[ |
|
732 |
('GRID',(0,0),(-1,-1),0.5,colors.grey), |
|
733 |
('ROWBACKGROUNDS', (0, 0), (-1, -1), (0xD0D0FF, None)), |
|
734 |
]) |
|
735 |
lst.append(t) |
|
736 |
lst.append(Spacer(0,6)) |
|
737 |
lst.append(Paragraph("And this should pale blue, pale pink and None by column", styleSheet['BodyText'])) |
|
738 |
data= [['001', '01', '02', '03', '04', '05'], |
|
739 |
['002', '01', '02', '03', '04', '05'], |
|
740 |
['003', '01', '02', '03', '04', '05'], |
|
741 |
['004', '01', '02', '03', '04', '05'], |
|
742 |
['005', '01', '02', '03', '04', '05'], |
|
743 |
['006', '01', '02', '03', '04', '05'], |
|
744 |
['007', '01', '02', '03', '04', '05'], |
|
745 |
['008', '01', '02', '03', '04', '05'], |
|
746 |
['009', '01', '02', '03', '04', '05'], |
|
747 |
['010', '01', '02', '03', '04', '05'], |
|
748 |
||
749 |
] |
|
750 |
t=Table(data,style=[ |
|
751 |
('GRID',(0,0),(-1,-1),0.5,colors.grey), |
|
752 |
('COLBACKGROUNDS', (0, 0), (-1, -1), (0xD0D0FF, 0xFFD0D0, None)), |
|
753 |
]) |
|
754 |
lst.append(t) |
|
755 |
||
756 |
lst.append(PageBreak()) |
|
757 |
lst.append(Paragraph("This spanning example illustrates automatic removal of grids and lines in spanned cells!", styleSheet['BodyText'])) |
|
758 |
lst.append(Spacer(0,6)) |
|
759 |
data= [['Top\nLeft', '', '02', '03', '04', '05', '06', '07'], |
|
760 |
['', '', '12', 'Span (3,1) (6,2)', '','','','17'], |
|
761 |
['20', '21', '22', '', '','','','27'], |
|
762 |
['30', '31', '32', '33', '34','35','36','37'], |
|
763 |
['40', 'In The\nMiddle', '', '', '44','45','46','47'], |
|
764 |
['50', '', '', '', '54','55','56','57'], |
|
765 |
['60', '', '', '','64', '65', 'Bottom\nRight', ''], |
|
766 |
['70', '71', '72', '73','74', '75', '', '']] |
|
767 |
t=Table(data,style=[ |
|
768 |
('GRID',(0,0),(-1,-1),0.5,colors.grey), |
|
769 |
('BACKGROUND',(0,0),(1,1),colors.palegreen), |
|
770 |
('SPAN',(0,0),(1,1)), |
|
771 |
('BACKGROUND',(-2,-2),(-1,-1), colors.pink), |
|
772 |
('SPAN',(-2,-2),(-1,-1)), |
|
773 |
('SPAN',(1,4),(3,6)), |
|
774 |
('BACKGROUND',(1,4),(3,6), colors.lightblue), |
|
775 |
('SPAN',(3,1),(6,2)), |
|
776 |
('BACKGROUND',(3,1),(6,2), colors.peachpuff), |
|
777 |
('VALIGN',(3,1),(6,2),'TOP'), |
|
778 |
('LINEABOVE', (0,2),(-1,2), 1, colors.black, 0, None, None, 2, 2), |
|
779 |
('LINEBEFORE', (3,0),(3,-1), 1, colors.black, 0, None, None, 2, 2), |
|
780 |
]) |
|
781 |
lst.append(t) |
|
782 |
||
783 |
lst.append(PageBreak()) |
|
784 |
||
785 |
lst.append(Paragraph("und jetzt noch eine Tabelle mit 5000 Zeilen:", styleSheet['BodyText'])) |
|
786 |
sty = [ ('GRID',(0,0),(-1,-1),1,colors.green), |
|
787 |
('BOX',(0,0),(-1,-1),2,colors.red), |
|
788 |
] |
|
3721 | 789 |
data = [[str(i), Paragraph("xx "* (i%10), styleSheet["BodyText"]), Paragraph("blah "*(i%40), styleSheet["BodyText"])] for i in range(500)] |
2963 | 790 |
t=LongTable(data, style=sty, colWidths = [50,100,200]) |
791 |
lst.append(t) |
|
792 |
||
793 |
#Yuan Hong's bug tester |
|
794 |
lst.append(PageBreak()) |
|
795 |
lst.append(Paragraph('Yian Hong\'s Bug Case (should not blow up)', styleSheet['Heading2'])) |
|
796 |
data = ([['Col1', 'Col2', 'Col3', 'Col4', 'Col5']]+ |
|
797 |
[['01', Paragraph('This is cell one that contains a paragraph.', styleSheet['Normal']), '02', '03', '04'] |
|
3721 | 798 |
for i in range(50)]) |
2963 | 799 |
|
800 |
t = Table(data, ['20%']*5, repeatRows=1) |
|
801 |
t.setStyle(TableStyle([ |
|
802 |
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
|
803 |
('BOX', (0,0), (-1,-1), 0.25, colors.black), |
|
804 |
('SPAN', (0,50), (-2,50)), |
|
805 |
])) |
|
806 |
||
807 |
lst.append(t) |
|
3461 | 808 |
lst.append(PageBreak()) |
2963 | 809 |
|
810 |
#Volker Haas' example extended |
|
811 |
#the optimal row heights are the solution of an LP similar to |
|
812 |
# |
|
813 |
#Objective function |
|
814 |
# min: 3*h0+3*h1+3*h2+2*h3; |
|
815 |
# |
|
816 |
#constraints |
|
817 |
# h0>=12; |
|
818 |
# h1>=12; |
|
819 |
# h2>=12; |
|
820 |
# h3>=12; |
|
821 |
# h0+h1+h2>=48; |
|
822 |
# h0+h1>=12; |
|
823 |
# h2+h3>=60; |
|
824 |
# |
|
825 |
#the solution H=[12,12,24,36] |
|
826 |
def makeTable(x,y): |
|
827 |
return Table([ |
|
828 |
['00', '01', '02', '03', '04', '05\nline2\nline3\nline4'], |
|
829 |
['', '11', '12', x, '',''], |
|
830 |
['20', '21', y, '23', '24',''], |
|
831 |
['30', '31', '', '33', '34','35'], |
|
832 |
], |
|
833 |
style=[ |
|
834 |
('TOPPADDING',(0,0),(-1,-1),0), |
|
835 |
('BOTTOMPADDING',(0,0),(-1,-1),0), |
|
836 |
('RIGHTPADDING',(0,0),(-1,-1),0), |
|
837 |
('LEFTPADDING',(0,0),(-1,-1),0), |
|
838 |
('GRID',(0,0),(-1,-1),0.5,colors.grey), |
|
839 |
('BACKGROUND', (0, 0), (0, 1), colors.pink), |
|
840 |
('SPAN',(0,0),(0,1)), |
|
841 |
('BACKGROUND', (2, 2), (2, 3), colors.orange), |
|
842 |
('SPAN',(2,2),(2,3)), |
|
843 |
('SPAN',(3,1),(4,1)), |
|
844 |
('SPAN',(5,0),(5,2)), |
|
845 |
]) |
|
846 |
p_style= ParagraphStyle('Normal') |
|
847 |
lst.append(makeTable( |
|
848 |
Paragraph('This is a string',p_style), |
|
849 |
Paragraph('22<br/>blub<br/>asfd<br/>afd<br/>asdfs', p_style) |
|
850 |
)) |
|
851 |
||
852 |
lst.append(Spacer(10,10)) |
|
853 |
lst.append(makeTable( |
|
854 |
XPreformatted('This is a string',p_style), |
|
855 |
Paragraph('22<br/>blub<br/>asfd<br/>afd<br/>asdfs', p_style) |
|
856 |
)) |
|
857 |
lst.append(Spacer(10,10)) |
|
858 |
lst.append(makeTable( |
|
859 |
'This is a string', |
|
860 |
'22\nblub\nasfd\nafd\nasdfs', |
|
861 |
)) |
|
862 |
lst.append(Spacer(10,10)) |
|
863 |
lst.append(makeTable( |
|
864 |
'This is a string', |
|
865 |
Paragraph('22<br/>blub<br/>asfd<br/>afd<br/>asdfs', p_style) |
|
866 |
)) |
|
3148 | 867 |
SimpleDocTemplate(outputfile('test_platypus_tables_2.pdf'), showBoundary=1).build(lst) |
2963 | 868 |
|
869 |
class TablesTestCase(unittest.TestCase): |
|
870 |
"Make documents with tables" |
|
871 |
||
872 |
def test0(self): |
|
4264
295afbf0f4c8
import Table _rowpositions calculation; version-->3.3.5
robin
parents:
4258
diff
changeset
|
873 |
"Make a document full of tables 0" |
2963 | 874 |
run() |
875 |
||
3149 | 876 |
def test1(self): |
4264
295afbf0f4c8
import Table _rowpositions calculation; version-->3.3.5
robin
parents:
4258
diff
changeset
|
877 |
"Make a document full of tables 1" |
2963 | 878 |
old_tables_test() |
879 |
||
4250
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
880 |
def test2(self): |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
881 |
'''buggy table example from Lele Gaifax https://bitbucket.org/lele/ |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
882 |
should split to two pages with the blue box on page 1 complete |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
883 |
''' |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
884 |
from reportlab.lib.pagesizes import A4, landscape |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
885 |
|
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
886 |
data = [ |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
887 |
['Date', '08 AM', '', '', '', '09 AM', '', '', '', '10 AM', '', '', '', '11 AM', '', '', '', '12 PM', '', '', '', '01 PM', '', '', '', '02 PM', '', '', '', '03 PM', '', '', '', '04 PM', '', '', '', '05 PM', '', '', '', '06 PM', '', '', '', '07 PM', '', '', '', '08 PM', '', '', '', '09 PM', '', '', '', '10 PM', '', '', '', '11 PM', '', '', ''], |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
888 |
['04-30-2015', '', '', '', '', '09:00 AM\n:\n01:00 PM\nSupervision\nReception', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''], |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
889 |
['05-01-2015', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '01:00 PM\n:\n04:00 PM\nSupervision\nInfo point 1', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''], |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
890 |
['05-03-2015', '', '', '', '', '09:00 AM\n:\n01:00 PM\nSupervision\nReception', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''], |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
891 |
['05-04-2015', '', '', '', '', '', '', '', '', '10:00 AM\n:\n01:00 PM\nSupervision\nInfo point 2', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '03:00 PM\n:\n05:30 PM\nSupervision\nInfo point 3', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''], |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
892 |
['05-05-2015', '', '', '', '', '09:00 AM\n:\n01:00 PM\nSupervision\nReception', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''], |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
893 |
['05-08-2015', '', '', '', '', '', '', '', '', '10:00 AM\n:\n01:00 PM\nSupervision\nInfo point 2', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '02:30 PM\n:\n05:30 PM\nSupervision\nInfo point 3', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''], |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
894 |
['05-10-2015', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '04:00 PM\n:\n08:00 PM\nSupervision\nInfo point 2', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''], |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
895 |
] |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
896 |
|
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
897 |
style = [ |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
898 |
('SPAN', (1, 0), (4, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
899 |
('SPAN', (5, 0), (8, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
900 |
('SPAN', (9, 0), (12, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
901 |
('SPAN', (13, 0), (16, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
902 |
('SPAN', (17, 0), (20, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
903 |
('SPAN', (21, 0), (24, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
904 |
('SPAN', (25, 0), (28, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
905 |
('SPAN', (29, 0), (32, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
906 |
('SPAN', (33, 0), (36, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
907 |
('SPAN', (37, 0), (40, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
908 |
('SPAN', (41, 0), (44, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
909 |
('SPAN', (45, 0), (48, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
910 |
('SPAN', (49, 0), (52, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
911 |
('SPAN', (53, 0), (56, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
912 |
('SPAN', (57, 0), (60, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
913 |
('SPAN', (61, 0), (64, 0)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
914 |
('SPAN', (1, -1), (4, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
915 |
('SPAN', (5, -1), (8, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
916 |
('SPAN', (9, -1), (12, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
917 |
('SPAN', (13, -1), (16, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
918 |
('SPAN', (17, -1), (20, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
919 |
('SPAN', (21, -1), (24, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
920 |
('SPAN', (25, -1), (28, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
921 |
('SPAN', (29, -1), (32, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
922 |
('SPAN', (33, -1), (36, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
923 |
('SPAN', (37, -1), (40, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
924 |
('SPAN', (41, -1), (44, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
925 |
('SPAN', (45, -1), (48, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
926 |
('SPAN', (49, -1), (52, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
927 |
('SPAN', (53, -1), (56, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
928 |
('SPAN', (57, -1), (60, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
929 |
('SPAN', (61, -1), (64, -1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
930 |
('ALIGN', (0, 0), (-1, -1), 'CENTER'), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
931 |
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
932 |
('SIZE', (0, 1), (0, -1), 8), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
933 |
('SIZE', (1, 1), (-1, -1), 6), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
934 |
('BOX', (5, 1), (20, 1), 1, colors.black), ('SPAN', (5, 1), (20, 1)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
935 |
('BOX', (21, 2), (32, 2), 1, colors.black), ('SPAN', (21, 2), (32, 2)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
936 |
('BOX', (5, 3), (20, 3), 1, colors.black), ('SPAN', (5, 3), (20, 3)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
937 |
('BOX', (9, 4), (20, 4), 1, colors.black), ('SPAN', (9, 4), (20, 4)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
938 |
('BOX', (29, 4), (38, 4), 1, colors.black), ('SPAN', (29, 4), (38, 4)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
939 |
('BOX', (5, 5), (20, 5), 1, colors.green), ('SPAN', (5, 5), (20, 5)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
940 |
('BOX', (9, 6), (20, 6), 1, colors.red), ('SPAN', (9, 6), (20, 6)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
941 |
('BOX', (27, 6), (38, 6), 1, colors.blue),('SPAN', (27, 6), (38, 6)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
942 |
('BOX', (33, 7), (48, 7), 1, colors.black),('SPAN', (33, 7), (48, 7)), |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
943 |
] |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
944 |
t = Table(data, colWidths=None, rowHeights=None, style=style, repeatRows=1) |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
945 |
doc = SimpleDocTemplate(outputfile('test_platypus_tables_issue74.pdf'), showBoundary=0, pagesize=landscape(A4)) |
3ed1ea9c1fc4
fix issue74 reported by Lele Gaifax https://bitbucket.org/lele/; version --> 3.2.18
robin
parents:
4067
diff
changeset
|
946 |
doc.build([t]) |
2963 | 947 |
|
948 |
def makeSuite(): |
|
949 |
return makeSuiteForClasses(TablesTestCase) |
|
950 |
||
951 |
||
952 |
#noruntests |
|
953 |
if __name__ == "__main__": |
|
954 |
unittest.TextTestRunner().run(makeSuite()) |
|
955 |
printLocation() |