author | rgbecker |
Wed, 12 Jul 2000 14:23:12 +0000 | |
changeset 356 | 377367fe28cb |
parent 354 | 807513dd52b7 |
child 357 | f1a45d837afb |
permissions | -rwxr-xr-x |
6 | 1 |
############################################################################### |
2 |
# |
|
3 |
# ReportLab Public License Version 1.0 |
|
4 |
# |
|
326 | 5 |
# Except for the change of names the spirit and intention of this |
6 |
# license is the same as that of Python |
|
6 | 7 |
# |
8 |
# (C) Copyright ReportLab Inc. 1998-2000. |
|
9 |
# |
|
10 |
# |
|
11 |
# All Rights Reserved |
|
12 |
# |
|
13 |
# Permission to use, copy, modify, and distribute this software and its |
|
14 |
# documentation for any purpose and without fee is hereby granted, provided |
|
15 |
# that the above copyright notice appear in all copies and that both that |
|
16 |
# copyright notice and this permission notice appear in supporting |
|
7 | 17 |
# documentation, and that the name of ReportLab not be used |
6 | 18 |
# in advertising or publicity pertaining to distribution of the software |
19 |
# without specific, written prior permission. |
|
20 |
# |
|
21 |
# |
|
22 |
# Disclaimer |
|
23 |
# |
|
24 |
# ReportLab Inc. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS |
|
25 |
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, |
|
26 |
# IN NO EVENT SHALL ReportLab BE LIABLE FOR ANY SPECIAL, INDIRECT |
|
27 |
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS |
|
28 |
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
|
29 |
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
30 |
# PERFORMANCE OF THIS SOFTWARE. |
|
31 |
# |
|
32 |
############################################################################### |
|
33 |
# $Log: tables.py,v $ |
|
356 | 34 |
# Revision 1.22 2000/07/12 14:23:12 rgbecker |
35 |
# Table argument order changed |
|
36 |
# |
|
354 | 37 |
# Revision 1.21 2000/07/12 09:05:17 rgbecker |
38 |
# Fixed tuple size bug |
|
356 | 39 |
# |
350 | 40 |
# Revision 1.20 2000/07/11 14:29:45 rgbecker |
41 |
# Table splitting start |
|
354 | 42 |
# |
342 | 43 |
# Revision 1.19 2000/07/10 15:25:47 andy_robinson |
44 |
# Added tables to PythonPoint |
|
350 | 45 |
# |
338 | 46 |
# Revision 1.18 2000/07/08 15:30:04 rgbecker |
47 |
# Cosmetics and error testing |
|
342 | 48 |
# |
333 | 49 |
# Revision 1.17 2000/07/07 16:22:10 rgbecker |
50 |
# Fix auto hieght stuff |
|
338 | 51 |
# |
329 | 52 |
# Revision 1.16 2000/07/07 10:23:36 rgbecker |
53 |
# First attempt at VALIGN |
|
333 | 54 |
# |
329 | 55 |
# Revision 1.15 2000/07/06 14:05:55 rgbecker |
327 | 56 |
# Adjusted doc string |
329 | 57 |
# |
58 |
# Revision 1.14 2000/07/06 12:41:47 rgbecker |
|
326 | 59 |
# First try at auto sizing |
327 | 60 |
# |
326 | 61 |
# Revision 1.13 2000/06/29 17:55:19 aaron_watters |
312 | 62 |
# support explicit \n line splitting in cells |
326 | 63 |
# |
64 |
# Revision 1.12 2000/06/13 13:03:31 aaron_watters |
|
268 | 65 |
# more documentation changes |
312 | 66 |
# |
326 | 67 |
# Revision 1.11 2000/06/01 15:23:06 rgbecker |
253 | 68 |
# Platypus re-organisation |
268 | 69 |
# |
326 | 70 |
# Revision 1.10 2000/05/26 09:49:23 rgbecker |
248 | 71 |
# Color fixes; thanks to J Alet |
253 | 72 |
# |
221 | 73 |
# Revision 1.9 2000/05/16 16:15:16 rgbecker |
74 |
# Changes related to removal of SimpleFlowDocument |
|
248 | 75 |
# |
168
02bac1346c69
Tables changed to use reportlab.lib.colors instead of
andy_robinson
parents:
129
diff
changeset
|
76 |
# Revision 1.8 2000/04/26 11:07:15 andy_robinson |
02bac1346c69
Tables changed to use reportlab.lib.colors instead of
andy_robinson
parents:
129
diff
changeset
|
77 |
# Tables changed to use reportlab.lib.colors instead of |
02bac1346c69
Tables changed to use reportlab.lib.colors instead of
andy_robinson
parents:
129
diff
changeset
|
78 |
# the six hard-coded color strings there previously. |
221 | 79 |
# |
129 | 80 |
# Revision 1.7 2000/04/14 12:17:05 rgbecker |
81 |
# Splitting layout.py |
|
168
02bac1346c69
Tables changed to use reportlab.lib.colors instead of
andy_robinson
parents:
129
diff
changeset
|
82 |
# |
128 | 83 |
# Revision 1.6 2000/04/14 11:54:57 rgbecker |
84 |
# Splitting layout.py |
|
129 | 85 |
# |
122 | 86 |
# Revision 1.5 2000/04/14 08:56:20 rgbecker |
87 |
# Drawable ==> Flowable |
|
128 | 88 |
# |
16 | 89 |
# Revision 1.4 2000/02/17 02:09:05 rgbecker |
90 |
# Docstring & other fixes |
|
122 | 91 |
# |
7 | 92 |
# Revision 1.3 2000/02/15 17:55:59 rgbecker |
93 |
# License text fixes |
|
16 | 94 |
# |
6 | 95 |
# Revision 1.2 2000/02/15 15:47:09 rgbecker |
96 |
# Added license, __version__ and Logi comment |
|
7 | 97 |
# |
356 | 98 |
__version__=''' $Id: tables.py,v 1.22 2000/07/12 14:23:12 rgbecker Exp $ ''' |
16 | 99 |
__doc__=""" |
6 | 100 |
Tables are created by passing the constructor a tuple of column widths, a tuple of row heights and the data in |
101 |
row order. Drawing of the table can be controlled by using a TableStyle instance. This allows control of the |
|
102 |
color and weight of the lines (if any), and the font, alignment and padding of the text. |
|
268 | 103 |
|
327 | 104 |
None values in the sequence of row heights or column widths, mean that the corresponding rows |
105 |
or columns should be automatically sized. |
|
106 |
||
107 |
All the cell values should be convertible to strings; embedded newline '\\n' characters |
|
108 |
cause the value to wrap (ie are like a traditional linefeed). |
|
109 |
||
268 | 110 |
See the test output from running this module as a script for a discussion of the method for constructing |
111 |
tables and table styles. |
|
6 | 112 |
""" |
253 | 113 |
from reportlab.platypus import * |
129 | 114 |
from reportlab.lib.styles import PropertySet, getSampleStyleSheet |
168
02bac1346c69
Tables changed to use reportlab.lib.colors instead of
andy_robinson
parents:
129
diff
changeset
|
115 |
from reportlab.lib import colors |
253 | 116 |
from reportlab.lib.pagesizes import DEFAULT_PAGE_SIZE |
312 | 117 |
import operator, string |
6 | 118 |
|
356 | 119 |
from types import TupleType, ListType |
6 | 120 |
_stringtype = type('') |
121 |
||
128 | 122 |
class CellStyle(PropertySet): |
326 | 123 |
defaults = { |
124 |
'fontname':'Times-Roman', |
|
125 |
'fontsize':10, |
|
126 |
'leading':12, |
|
127 |
'leftPadding':6, |
|
128 |
'rightPadding':6, |
|
129 |
'topPadding':3, |
|
130 |
'bottomPadding':3, |
|
131 |
'firstLineIndent':0, |
|
132 |
'color':colors.black, |
|
133 |
'alignment': 'LEFT', |
|
134 |
'background': (1,1,1), |
|
329 | 135 |
'valign': 'BOTTOM', |
326 | 136 |
} |
6 | 137 |
|
138 |
class TableStyle: |
|
326 | 139 |
def __init__(self, cmds=None): |
140 |
self._cmds = cmds |
|
141 |
if cmds is None: |
|
142 |
self._cmds = [] |
|
143 |
def add(self, *cmd): |
|
144 |
self._cmds.append(cmd) |
|
145 |
def getCommands(self): |
|
146 |
return self._cmds |
|
338 | 147 |
|
148 |
TableStyleType = type(TableStyle()) |
|
356 | 149 |
_SeqType = (TupleType, ListType) |
150 |
||
151 |
def _rowLen(x): |
|
152 |
return type(x) not in _SeqType and 1 or len(x) |
|
153 |
||
221 | 154 |
class Table(Flowable): |
356 | 155 |
def __init__(self, data, colWidths=None, rowHeights=None, style=None, |
350 | 156 |
repeatRows=0, repeatCols=0, splitByRow=1): |
356 | 157 |
nrows = len(data) |
158 |
if len(data)==0 or type(data) not in _SeqType: |
|
159 |
raise ValueError, "Table must have at least 1 row" |
|
160 |
ncols = max(map(_rowLen,data)) |
|
161 |
if not ncols: |
|
326 | 162 |
raise ValueError, "Table must have at least 1 column" |
356 | 163 |
if colWidths is None: colWidths = ncols*[None] |
164 |
elif len(colWidths) != ncols: |
|
165 |
raise ValueError, "Data error - %d columns in data but %d in grid" % (ncols, len(colWidths)) |
|
166 |
if rowHeights is None: rowHeights = nrows*[None] |
|
167 |
elif len(rowHeights) != nrows: |
|
168 |
raise ValueError, "Data error - %d rows in data but %d in grid" % (nrows, len(rowHeights)) |
|
169 |
self._nrows = nrows |
|
326 | 170 |
ncols = self._ncols = len(colWidths) |
171 |
for i in range(nrows): |
|
172 |
if len(data[i]) != ncols: |
|
173 |
raise ValueError, "Not enough data points in row %d!" % i |
|
350 | 174 |
self._rowHeights = self._argH = rowHeights |
175 |
self._colWidths = self._argW = colWidths |
|
326 | 176 |
self._cellvalues = data |
177 |
dflt = CellStyle('<default>') |
|
350 | 178 |
|
179 |
self._cellStyles = [None]*nrows |
|
326 | 180 |
for i in range(nrows): |
350 | 181 |
self._cellStyles[i] = [dflt]*ncols |
182 |
||
326 | 183 |
self._bkgrndcmds = [] |
184 |
self._linecmds = [] |
|
185 |
self._curweight = self._curcolor = self._curcellstyle = None |
|
350 | 186 |
self.repeatRows = repeatRows |
187 |
self.repeatCols = repeatCols |
|
188 |
self.splitByRow = splitByRow |
|
6 | 189 |
|
342 | 190 |
if style: |
191 |
self.setStyle(style) |
|
192 |
||
326 | 193 |
def _calc(self): |
333 | 194 |
|
350 | 195 |
H = self._argH |
196 |
W = self._argW |
|
6 | 197 |
|
326 | 198 |
if None in H: |
199 |
H = H[:] #make a copy as we'll change it |
|
333 | 200 |
self._rowHeights = H |
326 | 201 |
while None in H: |
202 |
i = H.index(None) |
|
203 |
V = self._cellvalues[i] |
|
350 | 204 |
S = self._cellStyles[i] |
326 | 205 |
h = 0 |
206 |
for v, s in map(None, V, S): |
|
207 |
if type(v) is not _stringtype: v = str(v) |
|
208 |
v = string.split(v, "\n") |
|
209 |
t = s.leading*len(v)+s.bottomPadding+s.topPadding |
|
210 |
if t>h: h = t #record a new maximum |
|
211 |
H[i] = h |
|
6 | 212 |
|
326 | 213 |
if None in W: |
214 |
W = W[:] |
|
215 |
self._colWidths = W |
|
216 |
while None in W: |
|
217 |
i = W.index(None) |
|
218 |
f = lambda x,i=i: operator.getitem(x,i) |
|
219 |
V = map(f,self._cellvalues) |
|
350 | 220 |
S = map(f,self._cellStyles) |
326 | 221 |
w = 0 |
222 |
for v, s in map(None, V, S): |
|
223 |
if type(v) is not _stringtype: v = str(v) |
|
224 |
v = string.split(v, "\n") |
|
225 |
t = s.leftPadding+s.rightPadding + max(map(lambda a, b=s.fontname, |
|
226 |
c=s.fontsize,d=self.canv: d.stringWidth(a,b,c), v)) |
|
227 |
if t>w: w = t #record a new maximum |
|
228 |
W[i] = w |
|
6 | 229 |
|
0 | 230 |
|
326 | 231 |
height = self._height = reduce(operator.add, H, 0) |
232 |
self._rowpositions = [height] # index 0 is actually topline; we skip when processing cells |
|
233 |
for h in H: |
|
234 |
height = height - h |
|
235 |
self._rowpositions.append(height) |
|
329 | 236 |
assert abs(height)<1e-8, 'Internal height error' |
326 | 237 |
width = 0 |
238 |
self._colpositions = [0] #index -1 is right side boundary; we skip when processing cells |
|
239 |
for w in W: |
|
240 |
width = width + w |
|
241 |
self._colpositions.append(width) |
|
242 |
self._width = width |
|
6 | 243 |
|
326 | 244 |
def setStyle(self, tblstyle): |
338 | 245 |
if type(tblstyle) is not TableStyleType: |
246 |
tblstyle = TableStyle(tblstyle) |
|
326 | 247 |
for cmd in tblstyle.getCommands(): |
350 | 248 |
self._addCommand(cmd) |
249 |
||
250 |
def _addCommand(self,cmd): |
|
251 |
if cmd[0] == 'BACKGROUND': |
|
252 |
self._bkgrndcmds.append(cmd) |
|
253 |
elif _isLineCommand(cmd): |
|
254 |
self._linecmds.append(cmd) |
|
255 |
else: |
|
256 |
(op, (sc, sr), (ec, er)), values = cmd[:3] , cmd[3:] |
|
257 |
if sc < 0: sc = sc + self._ncols |
|
258 |
if ec < 0: ec = ec + self._ncols |
|
259 |
if sr < 0: sr = sr + self._nrows |
|
260 |
if er < 0: er = er + self._nrows |
|
261 |
for i in range(sr, er+1): |
|
262 |
for j in range(sc, ec+1): |
|
263 |
_setCellStyle(self._cellStyles, i, j, op, values) |
|
326 | 264 |
|
265 |
def _drawLines(self): |
|
266 |
for op, (sc, sr), (ec, er), weight, color in self._linecmds: |
|
267 |
if sc < 0: sc = sc + self._ncols |
|
268 |
if ec < 0: ec = ec + self._ncols |
|
269 |
if sr < 0: sr = sr + self._nrows |
|
270 |
if er < 0: er = er + self._nrows |
|
271 |
if op == 'GRID': |
|
272 |
self._drawBox( (sc, sr), (ec, er), weight, color) |
|
273 |
self._drawInnerGrid( (sc, sr), (ec, er), weight, color) |
|
274 |
elif op in ('BOX', 'OUTLINE',): |
|
275 |
self._drawBox( (sc, sr), (ec, er), weight, color) |
|
276 |
elif op == 'INNERGRID': |
|
277 |
self._drawInnerGrid( (sc, sr), (ec, er), weight, color) |
|
278 |
elif op == 'LINEBELOW': |
|
279 |
self._drawHLines((sc, sr+1), (ec, er+1), weight, color) |
|
280 |
elif op == 'LINEABOVE': |
|
281 |
self._drawHLines((sc, sr), (ec, er), weight, color) |
|
282 |
elif op == 'LINEBEFORE': |
|
283 |
self._drawVLines((sc, sr), (ec, er), weight, color) |
|
284 |
elif op == 'LINEAFTER': |
|
285 |
self._drawVLines((sc+1, sr), (ec+1, er), weight, color) |
|
286 |
else: |
|
287 |
raise ValueError, "Unknown line style %s" % op |
|
288 |
self._curcolor = None |
|
248 | 289 |
|
326 | 290 |
def _drawBox(self, (sc, sr), (ec, er), weight, color): |
291 |
self._drawHLines((sc, sr), (ec, sr), weight, color) |
|
292 |
self._drawHLines((sc, er+1), (ec, er+1), weight, color) |
|
293 |
self._drawVLines((sc, sr), (sc, er), weight, color) |
|
294 |
self._drawVLines((ec+1, sr), (ec+1, er), weight, color) |
|
350 | 295 |
|
326 | 296 |
def _drawInnerGrid(self, (sc, sr), (ec, er), weight, color): |
297 |
self._drawHLines((sc, sr+1), (ec, er), weight, color) |
|
298 |
self._drawVLines((sc+1, sr), (ec, er), weight, color) |
|
350 | 299 |
|
326 | 300 |
def _prepLine(self, weight, color): |
301 |
if color != self._curcolor: |
|
302 |
self.canv.setStrokeColor(color) |
|
303 |
self._curcolor = color |
|
304 |
if weight != self._curweight: |
|
305 |
self.canv.setLineWidth(weight) |
|
306 |
self._curweight = weight |
|
350 | 307 |
|
326 | 308 |
def _drawHLines(self, (sc, sr), (ec, er), weight, color): |
309 |
self._prepLine(weight, color) |
|
310 |
scp = self._colpositions[sc] |
|
311 |
ecp = self._colpositions[ec+1] |
|
312 |
for rowpos in self._rowpositions[sr:er+1]: |
|
313 |
self.canv.line(scp, rowpos, ecp, rowpos) |
|
350 | 314 |
|
326 | 315 |
def _drawVLines(self, (sc, sr), (ec, er), weight, color): |
316 |
self._prepLine(weight, color) |
|
317 |
srp = self._rowpositions[sr] |
|
318 |
erp = self._rowpositions[er+1] |
|
319 |
for colpos in self._colpositions[sc:ec+1]: |
|
320 |
self.canv.line(colpos, srp, colpos, erp) |
|
321 |
||
322 |
def wrap(self, availWidth, availHeight): |
|
323 |
self._calc() |
|
324 |
#nice and easy, since they are predetermined size |
|
325 |
self.availWidth = availWidth |
|
326 |
return (self._width, self._height) |
|
350 | 327 |
|
328 |
def _cr_0(self,n,cmds): |
|
354 | 329 |
for c in cmds: |
330 |
c = tuple(c) |
|
331 |
(sc,sr), (ec,er) = c[1:3] |
|
350 | 332 |
if sr>=n: continue |
333 |
if er>=n: er = n-1 |
|
354 | 334 |
self._addCommand((c[0],)+((sc, sr), (ec, er))+c[3:]) |
350 | 335 |
|
336 |
def _cr_1_1(self,n,repeatRows, cmds): |
|
354 | 337 |
for c in cmds: |
338 |
c = tuple(c) |
|
339 |
(sc,sr), (ec,er) = c[1:3] |
|
350 | 340 |
if sr>=0 and sr>=repeatRows and sr<n and er>=0 and er<n: continue |
341 |
if sr>=repeatRows and sr<n: sr=repeatRows |
|
342 |
elif sr>=repeatRows and sr>=n: sr=sr+repeatRows-n |
|
343 |
if er>=repeatRows and er<n: er=repeatRows |
|
344 |
elif er>=repeatRows and er>=n: er=er+repeatRows-n |
|
354 | 345 |
self._addCommand((c[0],)+((sc, sr), (ec, er))+c[3:]) |
350 | 346 |
|
347 |
def _cr_1_0(self,n,cmds): |
|
354 | 348 |
for c in cmds: |
349 |
c = tuple(c) |
|
350 |
(sc,sr), (ec,er) = c[1:3] |
|
350 | 351 |
if er>=0 and er<n: continue |
352 |
if sr>=0 and sr<n: sr=0 |
|
353 |
if sr>=n: sr = sr-n |
|
354 |
if er>=n: er = er-n |
|
354 | 355 |
self._addCommand((c[0],)+((sc, sr), (ec, er))+c[3:]) |
350 | 356 |
|
357 |
def _splitRows(self,availHeight): |
|
358 |
self._calc() |
|
359 |
h = 0 |
|
360 |
n = 0 |
|
361 |
lim = len(self._rowHeights) |
|
362 |
while n<lim: |
|
363 |
hn = h + self._rowHeights[n] |
|
364 |
if hn>availHeight: break |
|
365 |
h = hn |
|
366 |
n = n + 1 |
|
367 |
||
368 |
if n<=self.repeatRows: |
|
369 |
return [] |
|
370 |
||
371 |
if n==lim: return [self] |
|
372 |
||
373 |
repeatRows = self.repeatRows |
|
374 |
repeatCols = self.repeatCols |
|
375 |
splitByRow = self.splitByRow |
|
376 |
data = self._cellvalues |
|
377 |
||
378 |
#we're going to split into two superRows |
|
356 | 379 |
R0 = Table( data[:n], self._argW, self._argH[:n], |
350 | 380 |
repeatRows=repeatRows, repeatCols=repeatCols, |
381 |
splitByRow=splitByRow) |
|
382 |
||
383 |
#copy the styles and commands |
|
384 |
R0._cellStyles = self._cellStyles[:n] |
|
385 |
R0._cr_0(n,self._linecmds) |
|
386 |
R0._cr_0(n,self._bkgrndcmds) |
|
387 |
||
388 |
if repeatRows: |
|
356 | 389 |
R1 = Table(data[:repeatRows]+data[n:], |
390 |
self._argW, self._argH[:repeatRows]+self._argH[n:], |
|
350 | 391 |
repeatRows=repeatRows, repeatCols=repeatCols, |
392 |
splitByRow=splitByRow) |
|
393 |
R1._cellStyles = self._cellStyles[:repeatRows]+self._cellStyles[n:] |
|
394 |
R1._cr_1_1(n,repeatRows,self._linecmds) |
|
395 |
R1._cr_1_1(n,repeatRows,self._bkgrndcmds) |
|
396 |
else: |
|
356 | 397 |
R1 = Table(data[n:], self._argW, self._argH[n:], |
350 | 398 |
repeatRows=repeatRows, repeatCols=repeatCols, |
399 |
splitByRow=splitByRow) |
|
400 |
R1._cellStyles = self._cellStyles[n:] |
|
401 |
R1._cr_1_0(n,self._linecmds) |
|
402 |
R1._cr_1_0(n,self._bkgrndcmds) |
|
403 |
||
404 |
return [R0,R1] |
|
405 |
||
406 |
def split(self, availWidth, availHeight): |
|
407 |
if self.splitByRow: |
|
408 |
if self._width>availWidth: return [] |
|
409 |
return self._splitRows(availHeight) |
|
410 |
else: |
|
411 |
raise NotImplementedError |
|
412 |
||
326 | 413 |
|
414 |
def draw(self): |
|
415 |
nudge = 0.5 * (self.availWidth - self._width) |
|
416 |
self.canv.translate(nudge, 0) |
|
417 |
self._drawBkgrnd() |
|
418 |
self._drawLines() |
|
350 | 419 |
for row, rowstyle, rowpos, rowheight in map(None, self._cellvalues, self._cellStyles, self._rowpositions[1:], self._rowHeights): |
326 | 420 |
for cellval, cellstyle, colpos, colwidth in map(None, row, rowstyle, self._colpositions[:-1], self._colWidths): |
421 |
self._drawCell(cellval, cellstyle, (colpos, rowpos), (colwidth, rowheight)) |
|
422 |
||
423 |
def _drawBkgrnd(self): |
|
424 |
for cmd, (sc, sr), (ec, er), color in self._bkgrndcmds: |
|
425 |
if sc < 0: sc = sc + self._ncols |
|
426 |
if ec < 0: ec = ec + self._ncols |
|
427 |
if sr < 0: sr = sr + self._nrows |
|
428 |
if er < 0: er = er + self._nrows |
|
429 |
color = colors.toColor(color, colors.Color(1,1,1)) |
|
430 |
x0 = self._colpositions[sc] |
|
431 |
y0 = self._rowpositions[sr] |
|
432 |
x1 = self._colpositions[ec+1] |
|
433 |
y1 = self._rowpositions[er+1] |
|
434 |
self.canv.setFillColor(color) |
|
435 |
self.canv.rect(x0, y0, x1-x0, y1-y0,stroke=0,fill=1) |
|
436 |
||
437 |
def _drawCell(self, cellval, cellstyle, (colpos, rowpos), (colwidth, rowheight)): |
|
438 |
#print "cellstyle is ", repr(cellstyle), id(cellstyle) |
|
439 |
if self._curcellstyle is not cellstyle: |
|
440 |
cur = self._curcellstyle |
|
441 |
if cur is None or cellstyle.color != cur.color: |
|
442 |
#print "setting cell color to %s" % `cellstyle.color` |
|
443 |
self.canv.setFillColor(cellstyle.color) |
|
444 |
if cur is None or cellstyle.leading != cur.leading or cellstyle.fontname != cur.fontname or cellstyle.fontsize != cur.fontsize: |
|
445 |
#print "setting font: %s, %s, %s" % (cellstyle.fontname, cellstyle.fontsize, cellstyle.leading) |
|
446 |
self.canv.setFont(cellstyle.fontname, cellstyle.fontsize, cellstyle.leading) |
|
447 |
self._curcellstyle = cellstyle |
|
448 |
#print "leading is ", cellstyle.leading, "size is", cellstyle.fontsize |
|
449 |
just = cellstyle.alignment |
|
450 |
#print "alignment is ", just |
|
451 |
if just == 'LEFT': |
|
452 |
draw = self.canv.drawString |
|
453 |
x = colpos + cellstyle.leftPadding |
|
454 |
elif just in ('CENTRE', 'CENTER'): |
|
455 |
draw = self.canv.drawCentredString |
|
456 |
x = colpos + colwidth * 0.5 |
|
338 | 457 |
elif just == 'RIGHT': |
326 | 458 |
draw = self.canv.drawRightString |
459 |
x = colpos + colwidth - cellstyle.rightPadding |
|
338 | 460 |
else: |
461 |
raise ValueError, 'Invalid justification %s' % just |
|
462 |
||
326 | 463 |
if type(cellval) is _stringtype: |
464 |
val = cellval |
|
465 |
else: |
|
466 |
val = str(cellval) |
|
467 |
vals = string.split(val, "\n") |
|
468 |
n = len(vals)-1 |
|
469 |
leading = cellstyle.leading |
|
329 | 470 |
valign = cellstyle.valign |
471 |
if valign=='BOTTOM': |
|
472 |
y = rowpos + cellstyle.bottomPadding+n*leading |
|
473 |
elif valign=='TOP': |
|
338 | 474 |
y = rowpos + rowheight - cellstyle.topPadding - cellstyle.fontsize |
329 | 475 |
elif valign=='MIDDLE': |
476 |
y = rowpos + (cellstyle.bottomPadding + rowheight - cellstyle.topPadding+n*leading)/2.0 |
|
477 |
else: |
|
478 |
raise ValueError, "Bad valign: '%s'" % str(valign) |
|
479 |
||
326 | 480 |
for v in vals: |
329 | 481 |
draw(x, y, v) |
482 |
y = y-leading |
|
326 | 483 |
|
6 | 484 |
# for text, |
326 | 485 |
# drawCentredString(self, x, y, text) where x is center |
486 |
# drawRightString(self, x, y, text) where x is right |
|
487 |
# drawString(self, x, y, text) where x is left |
|
6 | 488 |
|
489 |
LINECOMMANDS = ( |
|
326 | 490 |
'GRID', 'BOX', 'OUTLINE', 'INNERGRID', 'LINEBELOW', 'LINEABOVE', 'LINEBEFORE', 'LINEAFTER', ) |
6 | 491 |
|
492 |
||
493 |
def _isLineCommand(cmd): |
|
326 | 494 |
return cmd[0] in LINECOMMANDS |
6 | 495 |
|
350 | 496 |
def _setCellStyle(cellStyles, i, j, op, values): |
497 |
new = CellStyle('<%d, %d>' % (i,j), cellStyles[i][j]) |
|
498 |
cellStyles[i][j] = new |
|
326 | 499 |
if op == 'FONT': |
500 |
new.fontname = values[0] |
|
501 |
new.fontsize = values[1] |
|
502 |
elif op == 'TEXTCOLOR': |
|
503 |
new.color = colors.toColor(values[0], colors.Color(0,0,0)) |
|
504 |
elif op in ('ALIGN', 'ALIGNMENT'): |
|
505 |
new.alignment = values[0] |
|
329 | 506 |
elif op == 'VALIGN': |
507 |
new.valign = values[0] |
|
326 | 508 |
elif op == 'LEFTPADDING': |
509 |
new.leftPadding = values[0] |
|
510 |
elif op == 'RIGHTPADDING': |
|
511 |
new.rightPadding = values[0] |
|
512 |
elif op == 'TOPPADDING': |
|
513 |
new.topPadding = values[0] |
|
514 |
elif op == 'BOTTOMPADDING': |
|
515 |
new.bottomPadding = values[0] |
|
6 | 516 |
|
517 |
GRID_STYLE = TableStyle( |
|
326 | 518 |
[('GRID', (0,0), (-1,-1), 0.25, colors.black), |
519 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
520 |
) |
|
6 | 521 |
BOX_STYLE = TableStyle( |
326 | 522 |
[('BOX', (0,0), (-1,-1), 0.50, colors.black), |
523 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
524 |
) |
|
6 | 525 |
LABELED_GRID_STYLE = TableStyle( |
326 | 526 |
[('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
527 |
('BOX', (0,0), (-1,-1), 2, colors.black), |
|
528 |
('LINEBELOW', (0,0), (-1,0), 2, colors.black), |
|
529 |
('LINEAFTER', (0,0), (0,-1), 2, colors.black), |
|
530 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
531 |
) |
|
6 | 532 |
COLORED_GRID_STYLE = TableStyle( |
326 | 533 |
[('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
534 |
('BOX', (0,0), (-1,-1), 2, colors.red), |
|
535 |
('LINEBELOW', (0,0), (-1,0), 2, colors.black), |
|
536 |
('LINEAFTER', (0,0), (0,-1), 2, colors.black), |
|
537 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
538 |
) |
|
6 | 539 |
LIST_STYLE = TableStyle( |
326 | 540 |
[('LINEABOVE', (0,0), (-1,0), 2, colors.green), |
541 |
('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black), |
|
542 |
('LINEBELOW', (0,-1), (-1,-1), 2, colors.green), |
|
543 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
544 |
) |
|
6 | 545 |
|
546 |
def test(): |
|
329 | 547 |
from reportlab.lib.units import inch |
326 | 548 |
rowheights = (24, 16, 16, 16, 16) |
549 |
rowheights2 = (24, 16, 16, 16, 30) |
|
550 |
colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32) |
|
551 |
data = ( |
|
552 |
('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), |
|
553 |
('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), |
|
554 |
('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), |
|
555 |
('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), |
|
556 |
('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') |
|
557 |
) |
|
558 |
data2 = ( |
|
559 |
('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), |
|
560 |
('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), |
|
561 |
('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), |
|
562 |
('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), |
|
563 |
('Hats\nLarge', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') |
|
564 |
) |
|
565 |
styleSheet = getSampleStyleSheet() |
|
566 |
lst = [] |
|
567 |
lst.append(Paragraph("Tables", styleSheet['Heading1'])) |
|
568 |
lst.append(Paragraph(__doc__, styleSheet['BodyText'])) |
|
569 |
lst.append(Paragraph("The Tables (shown in different styles below) were created using the following code:", styleSheet['BodyText'])) |
|
570 |
lst.append(Preformatted(""" |
|
571 |
colwidths = (50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32) |
|
572 |
rowheights = (24, 16, 16, 16, 16) |
|
573 |
data = ( |
|
574 |
('', 'Jan', 'Feb', 'Mar','Apr','May', 'Jun', |
|
575 |
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), |
|
576 |
('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), |
|
577 |
('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), |
|
578 |
('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), |
|
579 |
('Hats', 893, 912, '1,212', 643, 789, 159, |
|
580 |
888, '1,298', 832, 453, '1,344','2,843') |
|
581 |
) |
|
356 | 582 |
t = Table(data, colwidths, rowheights) |
326 | 583 |
""", styleSheet['Code'], dedent=4)) |
584 |
lst.append(Paragraph(""" |
|
585 |
You can then give the Table a TableStyle object to control its format. The first TableStyle used was |
|
586 |
created as follows: |
|
587 |
""", styleSheet['BodyText'])) |
|
588 |
lst.append(Preformatted(""" |
|
6 | 589 |
GRID_STYLE = TableStyle( |
326 | 590 |
[('GRID', (0,0), (-1,-1), 0.25, colors.black), |
591 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
592 |
) |
|
593 |
""", styleSheet['Code'])) |
|
594 |
lst.append(Paragraph(""" |
|
595 |
TableStyles are created by passing in a list of commands. There are two types of commands - line commands |
|
596 |
and cell formatting commands. In all cases, the first three elements of a command are the command name, |
|
597 |
the starting cell and the ending cell. |
|
598 |
""", styleSheet['BodyText'])) |
|
599 |
lst.append(Paragraph(""" |
|
600 |
Line commands always follow this with the weight and color of the desired lines. Colors can be names, |
|
601 |
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 |
|
602 |
command names are: GRID, BOX, OUTLINE, INNERGRID, LINEBELOW, LINEABOVE, LINEBEFORE |
|
603 |
and LINEAFTER. BOX and OUTLINE are equivalent, and GRID is the equivalent of applying both BOX and |
|
604 |
INNERGRID. |
|
605 |
""", styleSheet['BodyText'])) |
|
606 |
lst.append(Paragraph(""" |
|
607 |
Cell formatting commands are: |
|
608 |
""", styleSheet['BodyText'])) |
|
609 |
lst.append(Paragraph(""" |
|
610 |
FONT - takes fontname, fontsize and (optional) leading. |
|
611 |
""", styleSheet['Definition'])) |
|
612 |
lst.append(Paragraph(""" |
|
613 |
TEXTCOLOR - takes a color name or (R,G,B) tuple. |
|
614 |
""", styleSheet['Definition'])) |
|
615 |
lst.append(Paragraph(""" |
|
616 |
ALIGNMENT (or ALIGN) - takes one of LEFT, RIGHT and CENTRE (or CENTER). |
|
617 |
""", styleSheet['Definition'])) |
|
618 |
lst.append(Paragraph(""" |
|
619 |
LEFTPADDING - defaults to 6. |
|
620 |
""", styleSheet['Definition'])) |
|
621 |
lst.append(Paragraph(""" |
|
622 |
RIGHTPADDING - defaults to 6. |
|
623 |
""", styleSheet['Definition'])) |
|
624 |
lst.append(Paragraph(""" |
|
625 |
BOTTOMPADDING - defaults to 3. |
|
626 |
""", styleSheet['Definition'])) |
|
627 |
lst.append(Paragraph(""" |
|
628 |
A tablestyle is applied to a table by calling Table.setStyle(tablestyle). |
|
629 |
""", styleSheet['BodyText'])) |
|
356 | 630 |
t = Table(data, colwidths, rowheights) |
326 | 631 |
t.setStyle(GRID_STYLE) |
632 |
lst.append(PageBreak()) |
|
633 |
lst.append(Paragraph("This is GRID_STYLE\n", styleSheet['BodyText'])) |
|
634 |
lst.append(t) |
|
635 |
||
356 | 636 |
t = Table(data, colwidths, rowheights) |
326 | 637 |
t.setStyle(BOX_STYLE) |
638 |
lst.append(Paragraph("This is BOX_STYLE\n", styleSheet['BodyText'])) |
|
639 |
lst.append(t) |
|
640 |
lst.append(Paragraph(""" |
|
641 |
It was created as follows: |
|
642 |
""", styleSheet['BodyText'])) |
|
643 |
lst.append(Preformatted(""" |
|
6 | 644 |
BOX_STYLE = TableStyle( |
326 | 645 |
[('BOX', (0,0), (-1,-1), 0.50, colors.black), |
646 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
647 |
) |
|
648 |
""", styleSheet['Code'])) |
|
649 |
||
356 | 650 |
t = Table(data, colwidths, rowheights) |
326 | 651 |
t.setStyle(LABELED_GRID_STYLE) |
652 |
lst.append(Paragraph("This is LABELED_GRID_STYLE\n", styleSheet['BodyText'])) |
|
653 |
lst.append(t) |
|
356 | 654 |
t = Table(data2, colwidths, rowheights2) |
326 | 655 |
t.setStyle(LABELED_GRID_STYLE) |
656 |
lst.append(Paragraph("This is LABELED_GRID_STYLE ILLUSTRATES EXPLICIT LINE SPLITTING WITH NEWLINE (different heights and data)\n", styleSheet['BodyText'])) |
|
657 |
lst.append(t) |
|
658 |
lst.append(Paragraph(""" |
|
659 |
It was created as follows: |
|
660 |
""", styleSheet['BodyText'])) |
|
661 |
lst.append(Preformatted(""" |
|
6 | 662 |
LABELED_GRID_STYLE = TableStyle( |
326 | 663 |
[('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
664 |
('BOX', (0,0), (-1,-1), 2, colors.black), |
|
665 |
('LINEBELOW', (0,0), (-1,0), 2, colors.black), |
|
666 |
('LINEAFTER', (0,0), (0,-1), 2, colors.black), |
|
667 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
668 |
) |
|
669 |
""", styleSheet['Code'])) |
|
670 |
lst.append(PageBreak()) |
|
671 |
||
356 | 672 |
t = Table(data, colwidths, rowheights) |
326 | 673 |
t.setStyle(COLORED_GRID_STYLE) |
674 |
lst.append(Paragraph("This is COLORED_GRID_STYLE\n", styleSheet['BodyText'])) |
|
675 |
lst.append(t) |
|
676 |
lst.append(Paragraph(""" |
|
677 |
It was created as follows: |
|
678 |
""", styleSheet['BodyText'])) |
|
679 |
lst.append(Preformatted(""" |
|
6 | 680 |
COLORED_GRID_STYLE = TableStyle( |
326 | 681 |
[('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
682 |
('BOX', (0,0), (-1,-1), 2, colors.red), |
|
683 |
('LINEBELOW', (0,0), (-1,0), 2, colors.black), |
|
684 |
('LINEAFTER', (0,0), (0,-1), 2, colors.black), |
|
685 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
686 |
) |
|
687 |
""", styleSheet['Code'])) |
|
688 |
||
356 | 689 |
t = Table(data, colwidths, rowheights) |
326 | 690 |
t.setStyle(LIST_STYLE) |
691 |
lst.append(Paragraph("This is LIST_STYLE\n", styleSheet['BodyText'])) |
|
692 |
lst.append(t) |
|
693 |
lst.append(Paragraph(""" |
|
694 |
It was created as follows: |
|
695 |
""", styleSheet['BodyText'])) |
|
696 |
lst.append(Preformatted(""" |
|
6 | 697 |
LIST_STYLE = TableStyle( |
326 | 698 |
[('LINEABOVE', (0,0), (-1,0), 2, colors.green), |
699 |
('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black), |
|
700 |
('LINEBELOW', (0,-1), (-1,-1), 2, colors.green), |
|
701 |
('ALIGN', (1,1), (-1,-1), 'RIGHT')] |
|
702 |
) |
|
703 |
""", styleSheet['Code'])) |
|
6 | 704 |
|
356 | 705 |
t = Table(data, colwidths, rowheights) |
326 | 706 |
ts = TableStyle( |
707 |
[('LINEABOVE', (0,0), (-1,0), 2, colors.green), |
|
708 |
('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black), |
|
709 |
('LINEBELOW', (0,-1), (-1,-1), 2, colors.green), |
|
710 |
('ALIGN', (1,1), (-1,-1), 'RIGHT'), |
|
711 |
('TEXTCOLOR', (0,1), (0,-1), colors.red), |
|
712 |
('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))] |
|
713 |
) |
|
714 |
t.setStyle(ts) |
|
715 |
lst.append(Paragraph("This is a custom style\n", styleSheet['BodyText'])) |
|
716 |
lst.append(t) |
|
717 |
lst.append(Paragraph(""" |
|
718 |
It was created as follows: |
|
719 |
""", styleSheet['BodyText'])) |
|
720 |
lst.append(Preformatted(""" |
|
6 | 721 |
ts = TableStyle( |
326 | 722 |
[('LINEABOVE', (0,0), (-1,0), 2, colors.green), |
723 |
('LINEABOVE', (0,1), (-1,-1), 0.25, colors.black), |
|
724 |
('LINEBELOW', (0,-1), (-1,-1), 2, colors.green), |
|
725 |
('ALIGN', (1,1), (-1,-1), 'RIGHT'), |
|
726 |
('TEXTCOLOR', (0,1), (0,-1), colors.red), |
|
727 |
('BACKGROUND', (0,0), (-1,0), colors.Color(0,0.7,0.7))] |
|
728 |
) |
|
729 |
""", styleSheet['Code'])) |
|
730 |
data = ( |
|
731 |
('', 'Jan\nCold', 'Feb\n', 'Mar\n','Apr\n','May\n', 'Jun\nHot', 'Jul\n', 'Aug\nThunder', 'Sep\n', 'Oct\n', 'Nov\n', 'Dec\n'), |
|
732 |
('Mugs', 0, 4, 17, 3, 21, 47, 12, 33, 2, -2, 44, 89), |
|
733 |
('T-Shirts', 0, 42, 9, -3, 16, 4, 72, 89, 3, 19, 32, 119), |
|
734 |
('Key Ring', 0,0,0,0,0,0,1,0,0,0,2,13), |
|
735 |
('Hats', 893, 912, '1,212', 643, 789, 159, 888, '1,298', 832, 453, '1,344','2,843') |
|
736 |
) |
|
737 |
c = list(colwidths) |
|
738 |
c[0] = None |
|
739 |
c[8] = None |
|
356 | 740 |
t = Table(data, c, [None]+list(rowheights[1:])) |
326 | 741 |
t.setStyle(LIST_STYLE) |
742 |
lst.append(Paragraph(""" |
|
743 |
This is a LIST_STYLE table with the first rowheight set to None ie automatic. |
|
744 |
The top row cells are split at a newline '\\n' character. The first and August |
|
745 |
column widths were also set to None. |
|
746 |
""", styleSheet['BodyText'])) |
|
747 |
lst.append(t) |
|
329 | 748 |
lst.append(Paragraph(""" |
749 |
The red numbers should be aligned LEFT & BOTTOM, the blue RIGHT & TOP |
|
750 |
and the green CENTER & MIDDLE. |
|
751 |
""", styleSheet['BodyText'])) |
|
338 | 752 |
data= [['X00y', 'X01y', 'X02y', 'X03y', 'X04y'], |
753 |
['X10y', 'X11y', 'X12y', 'X13y', 'X14y'], |
|
754 |
['X20y', 'X21y', 'X22y', 'X23y', 'X24y'], |
|
755 |
['X30y', 'X31y', 'X32y', 'X33y', 'X34y']] |
|
356 | 756 |
t=Table(data, 5*[0.4*inch], 4*[0.4*inch]) |
338 | 757 |
t.setStyle([('ALIGN',(1,1),(-2,-2),'LEFT'), |
758 |
('TEXTCOLOR',(1,1),(-2,-2),colors.red), |
|
759 |
||
760 |
('VALIGN',(0,0),(1,-1),'TOP'), |
|
761 |
('ALIGN',(0,0),(1,-1),'RIGHT'), |
|
762 |
('TEXTCOLOR',(0,0),(1,-1),colors.blue), |
|
763 |
||
764 |
('ALIGN',(0,-1),(-1,-1),'CENTER'), |
|
765 |
('VALIGN',(0,-1),(-1,-1),'MIDDLE'), |
|
766 |
('TEXTCOLOR',(0,-1),(-1,-1),colors.green), |
|
767 |
||
768 |
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
|
769 |
('BOX', (0,0), (-1,-1), 0.25, colors.black), |
|
770 |
]) |
|
329 | 771 |
lst.append(t) |
333 | 772 |
data = [('alignment', 'align\012alignment'), |
773 |
('bulletColor', 'bulletcolor\012bcolor'), |
|
774 |
('bulletFontName', 'bfont\012bulletfontname'), |
|
775 |
('bulletFontSize', 'bfontsize\012bulletfontsize'), |
|
776 |
('bulletIndent', 'bindent\012bulletindent'), |
|
777 |
('firstLineIndent', 'findent\012firstlineindent'), |
|
778 |
('fontName', 'face\012fontname\012font'), |
|
779 |
('fontSize', 'size\012fontsize'), |
|
780 |
('leading', 'leading'), |
|
781 |
('leftIndent', 'leftindent\012lindent'), |
|
782 |
('rightIndent', 'rightindent\012rindent'), |
|
783 |
('spaceAfter', 'spaceafter\012spacea'), |
|
784 |
('spaceBefore', 'spacebefore\012spaceb'), |
|
785 |
('textColor', 'fg\012textcolor\012color')] |
|
356 | 786 |
t = Table(data) |
338 | 787 |
t.setStyle([ |
333 | 788 |
('VALIGN',(0,0),(-1,-1),'TOP'), |
789 |
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
|
790 |
('BOX', (0,0), (-1,-1), 0.25, colors.black), |
|
338 | 791 |
]) |
333 | 792 |
lst.append(t) |
356 | 793 |
t=apply(Table,([('Attribute', 'Synonyms'), ('alignment', 'align, alignment'), ('bulletColor', 'bulletcolor, bcolor'), ('bulletFontName', 'bfont, bulletfontname'), ('bulletFontSize', 'bfontsize, bulletfontsize'), ('bulletIndent', 'bindent, bulletindent'), ('firstLineIndent', 'findent, firstlineindent'), ('fontName', 'face, fontname, font'), ('fontSize', 'size, fontsize'), ('leading', 'leading'), ('leftIndent', 'leftindent, lindent'), ('rightIndent', 'rightindent, rindent'), ('spaceAfter', 'spaceafter, spacea'), ('spaceBefore', 'spacebefore, spaceb'), ('textColor', 'fg, textcolor, color')],)) |
350 | 794 |
t.repeatRows = 1 |
795 |
t.setStyle([ |
|
796 |
('FONT',(0,0),(-1,1),'Times-Bold',10,12), |
|
797 |
('FONT',(0,1),(-1,-1),'Courier',8,8), |
|
798 |
('VALIGN',(0,0),(-1,-1),'MIDDLE'), |
|
799 |
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
|
800 |
('BOX', (0,0), (-1,-1), 0.25, colors.black), |
|
354 | 801 |
('BACKGROUND', (0, 0), (-1, 0), colors.green), |
802 |
('BACKGROUND', (0, 1), (-1, -1), colors.pink), |
|
803 |
('ALIGN', (0, 0), (-1, 0), 'CENTER'), |
|
804 |
('ALIGN', (0, 1), (0, -1), 'LEFT'), |
|
805 |
('ALIGN', (-1, 1), (-1, -1), 'RIGHT'), |
|
806 |
('FONT', (0, 0), (-1, 0), 'Times-Bold', 12), |
|
807 |
('ALIGN', (1, 1), (1, -1), 'CENTER'), |
|
350 | 808 |
]) |
809 |
lst.append(t) |
|
356 | 810 |
SimpleDocTemplate('tables.pdf', showBoundary=1).build(lst) |
6 | 811 |
|
812 |
if __name__ == '__main__': |
|
326 | 813 |
test() |