Código
var
shtml : widestring;
htmlfile : TextFile;
i : integer;
AvailableFields: set of TFieldType;
bookmark : tbookmarkstr;
begin
bookmark := dataset.Bookmark;
DataSet.DisableControls;
DataSet.First;
AvailableFields:=[ftInteger, ftWideString, ftDate, ftBcd, ftmemo, ftstring];
// --> cria o código html da página
shtml:= '<html> <head>'+#13#10;
shtml:= shtml + '<title>'+dataset.Name+'</title></head>' + #13#10;
shtml:= shtml + '<body>' + #13#10;
shtml:= shtml + '<script>'+#13+'function cor_tabela(id){'+#13+
'var cor1="#dae5e3";'+#13+
'var cor2="#fff";'+#13+
'var x=document.getElementById(id).getElementsByTagName("tr");'+#13+
'for(i=0;i<x.length;i++)'+#13+
'x[i].style.backgroundColor=(i%2==0)?cor1:cor2;'+#13+
'}'+#13+
'</script>'+#13+#10;
shtml:= shtml + '<style>'+#13+
'table {'+#13+
'border:solid 1px #000;'+#13+
'font-family:Verdana, Geneva, sans-serif;'+#13+
'font-size:11px;'+#13+
'background:#930;'+#13+
'}'+#13+
'th {'+#13+
'color:#FFF;'+#13+
'background:#930;'+#13+
'height:25px;'+#13+
'vertical-align:middle;'+#13+
'}'+#13+
'</style>'+#13+#10;
//header da tabela
shtml:= shtml + '<table id="tb" cellspacing="1" width="100%">' + #13#10;
shtml:= shtml + '<tr>' + #13#10;
for i:=0 to DataSet.FieldCount-1 do
begin
if DataSet.Fields[i].DataType in AvailableFields then
begin
shtml:= shtml + '<th>';
shtml:= shtml +
'' +
DataSet.Fields.Fields[i].DisplayName +
'';
shtml:= shtml + '</th>' + #13#10;
end;
end;{for}
shtml:= shtml + '</tr>' + #13#10;
//corpo da tabela
while not DataSet.Eof do
begin
shtml:= shtml + '<tr>' + #13#10;
for i:=0 to DataSet.FieldCount-1 do
begin
if DataSet.Fields.Fields[i].DataType in AvailableFields then
begin
if DataSet.Fields.Fields[i].DataType = ftBcd then
begin
shtml:= shtml + '<td align="right">'+ formatfloat('R$ ###,##0.00', DataSet.Fields.Fields[i].AsCurrency);
end else
begin
shtml:= shtml + '<td>'+DataSet.Fields.Fields[i].AsString;
shtml:= shtml + '</td>' + #13#10;
end;
end;
end;{for}
shtml:= shtml + '</tr>' + #13#10;
DataSet.Next;
end;{while}
shtml:= shtml + '</table>' + #13#10;
//script para zebrar a tabela
shtml:= shtml + '<script>cor_tabela("tb");</script>'+#13+#10;
//finalizando a página
shtml:= shtml + '</body></html>';
// --> salva o arquivo html
AssignFile(htmlfile,ChangeFileExt(Arq,'.'+Ext));
Rewrite(htmlfile);
WriteLn(htmlfile, shtml);
CloseFile(htmlfile);
DataSet.Bookmark := bookmark;
DataSet.EnableControls;
end;
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009