您现在的位置:首页 >> 基础算法 >> window基础 >> 内容

Delphi中把数据集转成HTML中的表格

时间:2011/9/3 15:31:58 点击:

  核心提示:function GetTD(S: string): string;begin if S = '' then S := 'nbsp;'; Result := 'td' + S + '/td';end;...

function GetTD(S: string): string;
begin
  if S = '' then S := ' ';
  Result := '<td>' + S + '</td>';
end;

function GetTR(S: string): string;
begin
  Result := '<tr>' + S + '</tr>';
end;

function GetTDNOWRAP(S: string): string;
begin
  if S = '' then S := '&nbsp;';
  Result := '<td nowrap>' + S + '</td>';
end;

function FormatHTMLData(const Obj: TDataSet): string;
var
  SL:TStringList;
  HTMLLine:string;
  j:Integer;
begin
  SL:=TStringList.Create;
  try
    SL.Add('<table border="1" cellspacing="1" bordercolor="#71C1E2" style="border-collapse: collapse">');
    HTMLLine := '';
    for j := 0 to Obj.FieldCount - 1 do
    begin
      HTMLLine := HTMLLine + GetTDNOWRAP(Obj.Fields[j].DisplayName);
    end;
    HTMLLine := GetTR(HTMLLine);
    SL.Add(HTMLLine);
    Obj.First;
    while not Obj.eof do
    begin
      HTMLLine := '';
      for j := 0 to Obj.FieldCount - 1 do
      begin
        HTMLLine := HTMLLine + GetTDNOWRAP(Obj.Fields[j].AsString);
      end;
      HTMLLine := GetTR(HTMLLine);
      SL.Add(HTMLLine);
      Obj.NEXT;
    end;
    SL.Add('</table>');
    Result:=SL.Text;
  finally
    if Assigned(SL) then FreeAndNil(SL);
  end;
end;

作者:站长 来源:原创
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号