1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.pagesizes import A4
from reportlab.platypus import Paragraph, SimpleDocTemplate,Table, TableStyle, Image, Spacer
from reportlab.lib.units import cm
from reportlab.lib import colors
def myTable(tabledata):
#first define column and row size
nbligns = []
nbcols = []
for i in range(len(tabledata)):
nbligns.append(15)
for i in range(len(tabledata[0])):
nbcols.append(100)
t = Table(tabledata, nbcols, nbligns)
GRID_STYLE = TableStyle([
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0,0), (-1,-1), 0.25, colors.black),
('BACKGROUND',(0,0),(4,0),colors.lightgrey),
('ALIGN', (0, 1), (-1, -1), "CENTER"),
('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
('FONTSIZE', (0,0), (-1, -1), 10)
])
t.setStyle(GRID_STYLE)
t.hAlign=1
return t
####
styles = getSampleStyleSheet()
styleT = styles['Title']
styleH1 = styles['Heading1']
styleH2 = styles['Heading2']
styleH3 = styles['Heading3']
styleH4 = styles['Heading4']
styleN = styles['Normal']
#####
contenue = []
numcapteur = 25
text="Post traitement du raccordement de l'Hélice "+str(numcapteur)
contenue.append(Paragraph(text, styleT))
contenue.append(Paragraph("Ceci est la section", styleH1))
contenue.append(Paragraph("Information sur le traitement des paliers", styleH2))
text="Bon voici du blabla:\\n encore un peu, et la aussi.\
<br/>\nPrend t'il les saut de lignes en compte.<br/>\n\
On continue histoire de vois ce qui ce passe\
au bout de la ligne."
contenue.append(Paragraph(text, styleN))
contenue.append(Spacer(1, .6*cm))
entete = [("Paliers trouvés","Moyenne [V]","Ecart-type [mV]","Nb de valeurs/palier")]
donneestraitees = [('0', '0.0153', '0.0441', '110'), ('1', '0.2565', '0.7945', '126'), ('2', '0.4967', '0.8953', '135'), ('3', '0.9578', '1.7179', '133'), ('4', '1.4443', '3.599', '131'), ('3', '0.9573', '3.014', '134'), ('2', '0.4996', '0.9662', '133'), ('1', '0.2615', '0.4546', '137'), ('0', '0.0071', '5.7935', '139')]
data = entete+donneestraitees
t=Table(data, len(data)*[1*cm], len(data)*[0.6*cm])
t.setStyle(TableStyle([]))
contenue.append(myTable(data))
contenue.append(Spacer(1, .6*cm))
contenue.append(Paragraph("Voici la suite", styleN))
contenue.append(Image('foo.png', height = 480*0.6, width = 640*0.6))
doc = SimpleDocTemplate('test.pdf',pagesize = A4,
title = 'Premier test',
author = 'Moi' )
doc.build(contenue) |
Partager