VCL Delphi

Title: How to convert a TStringGrid to HTML
procedure SGridToHtml(SG: TStringgrid; Dest: TMemo; BorderSize: Integer);
var
i, p: integer;
SStyle1, SStyle2, Text: string;
begin
Dest.Clear;
Dest.Lines.Add('');
Dest.Lines.Add('');
Dest.Lines.Add(' + IntToStr(BorderSize) + '" width="' +
IntToStr(SG.Width) + '" height="' + IntToStr(SG.Width) + '"');
for i := 0 to SG.RowCount - 1 do
begin
Dest.Lines.Add(' ');
for p := 0 to SG.ColCount - 1 do
begin
SStyle1 := '';
SStyle2 := '';
if fsbold in SG.Font.Style then
begin
SStyle1 := SStyle1 + '';
SStyle2 := SStyle2 + '';
end;
if fsitalic in SG.Font.Style then
begin
SStyle1 := SStyle1 + '';
SStyle2 := SStyle2 + '';
end;
if fsunderline in SG.Font.Style then
begin
SStyle1 := SStyle1 + '';
SStyle2 := SStyle2 + '';
end;
Text := sg.Cells[p, i];
if Text = '' then Text := ' ';
Dest.Lines.Add(' + IntToStr(sg.ColWidths[p]) +
'" height="' + IntToStr(sg.RowHeights[p]) +
'" + IntToHex(sg.Font.Color, 6) +
'" face="' + SG.Font.Name + '"' + SStyle1 +
Text + SStyle2 + '');
end;
Dest.Lines.Add(' ');
end;
Dest.Lines.Add(' ');
Dest.Lines.Add('');;
Dest.Lines.Add('');
end;
Usage Example:
procedure TFormCSVInport.Button6Click(Sender: TObject);
begin
SGridToHtml(StringGrid1, Memo1, 1);
Memo1.Lines.SaveToFile('c:\test.html');
end;