uses ExtCtrls, Grids
//
Procedure SGridToHtml(SG:Tstringgrid; Dest:TMemo; BorderSize:integer);
var i,p:integer;
SStyle1,SStyle2,Text:string;
begin
Dest.Clear;
Dest.lines.add('<html>');
Dest.lines.add('<body>');
Dest.lines.add(' <table border="'+inttostr(BorderSize)+
'"width="'+inttostr(SG.Width)+'" height="'+inttostr(SG.Width)+'">');
for i:=0 to SG.RowCount-1 do
begin
Dest.lines.add(' <tr>');
for p:=0 to SG.ColCount-1 do
begin
SStyle1:='';
SStyle2:='';
if fsbold in SG.Font.style then
begin
SStyle1:=SStyle1+'<b>';
SStyle2:=SStyle2+'</b>';
end;
if fsitalic in SG.Font.style then
begin
SStyle1:=SStyle1+'<i>';
SStyle2:=SStyle2+'</i>';
end;
if fsunderline in SG.Font.style then
begin
SStyle1:=SStyle1+'<u>';
SStyle2:=SStyle2+'</u>';
end;
text:=sg.Cells[p,i];
if text='' then
text:=' ' ;
Dest.lines.add(' <td width="'+inttostr(sg.ColWidths[p])+
'" height="'+inttostr(sg.RowHeights[p])+
'"><font color="#'+inttohex(sg.Font.Color,6)+
'" face="'+SG.Font.Name+'">'+SStyle1+
text+SStyle2+'</font></td>');
end;
Dest.lines.add(' </tr>');
end;
Dest.lines.add(' </table>');
Dest.lines.add('</body>');;
Dest.lines.add('</html>');
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
if SaveDialog1.Execute then begin
SGridToHtml(StringGrid1, Memo1,1);
Memo1.Lines.SaveToFile(SaveDialog1.FileName + '.html');
end;
end;
Keine Kommentare:
Kommentar veröffentlichen