Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: VCL / WinForms / Controls (https://www.delphipraxis.net/24-library-vcl-winforms-controls/)
-   -   Delphi ein TStringGrid in eine HTML Datei umwandeln? (https://www.delphipraxis.net/22851-ein-tstringgrid-eine-html-datei-umwandeln.html)

CTV 25. Mai 2004 09:41


ein TStringGrid in eine HTML Datei umwandeln?
 
Mit dieser Procedure kann man ein Stringgrid in eine html Datei umwandeln
Delphi-Quellcode:
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;


procedure TFormCSVInport.Button6Click(Sender: TObject);
begin
  SGridToHtml(StringGrid1,Memo1,1);
  memo1.Lines.SaveToFile('c:\test.html');
end;
Viel Spass
Greez Cyrus
Copyright by Cyrus


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:22 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz