procedure DBGrid1ToHTML(aFDquery :TFDQuery;aHTMLFileName:string);
var
  aHTMLtext: TstringList;
   j: integer;
begin
  aHTMLtext := TstringList.Create;
  aHTMLtext.Add
    ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  ' +
    '<html>   <head>    <title></title>   </head>  ' +
    '  <body>  <table border=".5pt solid windowtext;"; > ' +
    ' <col width=72 span=3 style='' width:54pt''>');

  aHTMLtext.Add(' <tr > ');
    for j := 1 to aFDquery.FieldCount do
    begin
      aHTMLtext.Add('<td>');
      aHTMLtext.Add(aFDquery.Fields.FieldByNumber(j).FieldName);   //  列 名
      aHTMLtext.Add('</td>');
    end;
  aHTMLtext.Add(' </tr> ');

  aFDquery.First;
  while not(aFDquery.Eof) do
  begin
    aHTMLtext.Add(' <tr  > ');

    for j := 1 to aFDquery.FieldCount do
    begin
      aHTMLtext.Add('<td>');
      aHTMLtext.Add(aFDquery.Fields.FieldByNumber(j).AsString);   //  列  值
      aHTMLtext.Add('</td>');
    end;
    aHTMLtext.Add(' </tr> ');

    aFDquery.Next;
  end;

  aHTMLtext.Add('</table>  </body>  </html> ');
  aHTMLtext.SaveToFile(aHTMLFileName);
  aHTMLtext.Free;
end;