Einzelnen Beitrag anzeigen

Benutzerbild von CTV
CTV

Registriert seit: 20. Jan 2004
Ort: Zug CH
83 Beiträge
 
Delphi 7 Professional
 
#1

ein TStringGrid in eine HTML Datei umwandeln?

  Alt 25. Mai 2004, 09:41
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
Wer glaub er ist, hört auf zu werden!
Delphi Rulez!!!
  Mit Zitat antworten Zitat