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
|
procedure prepareRapport;
var
SL : TStringList; // va recevoir le modèle original
SL1 : TStringList; // lignes du fichier final
i : Integer;
begin
SL := TStringList.Create;
SL.LoadFromFile('modele.html');
SL1:=TStringList.Create;
for i:=0 to SL.Count-1 do
begin
SL[i]:=StringReplace(SL[i],'[client]','TOTO',[rfReplaceAll]); // remplacement facile
// Cases à cocher
if client then
SL[i]:=StringReplace(SL[i],'name="Client"','checked=""',[rfReplaceAll]);
if not client then
SL[i]:=StringReplace(SL[i],'name="Prospect"','checked=""',[rfReplaceAll]);
if pos('[listecontacts]',sl[i])>0 then // remplacement par une table html
begin
SL1.Add(Format('<table style="text-align: left; width: 100%%; height: %dpx border="1" cellpadding="2" cellspacing="2"><tbody>',[4*26]));
SL1.Add(Format('<tr><td style="text-align: center;width: 597px;"><b>%s</b></td><td style="width: 425px;"><b>%s</b></td></tr>',['Prénom, Nom','Fonction']));
// remplir liste
SL1.Add(Format('<tr><td style="text-align: center;width: 597px;">%s</td><td style="width: 425px;">%s</td></tr>',['toto, Tata','Direction']));
SL1.Add(Format('<tr><td style="text-align: center;width: 597px;">%s</td><td style="width: 425px;">%s</td></tr>',['titi, Tata','Ventes']));
SL1.Add(Format('<tr><td style="text-align: center;width: 597px;">%s</td><td style="width: 425px;">%s</td></tr>',['tutu, Tata','Achats']));
SL[i]:='</tbody></table>';
end;
SL1.Add(SL[i]);
end;
.....
SL.Free;
SL1.SaveToFile('rapport.html');
SL1.Free;
end; |
Partager