Gerar tabela em html

Delphi

17/12/2003

Como posso criar um arquivo html lendo de uma tabela ?

Obrigado


Gveggi

Gveggi

Curtidas 0

Respostas

Nigro

Nigro

17/12/2003

A forma mais fácil, nem sempre é a melhor, eu faço da seguinte forma:
Crio uma tStringList, e vou adicionando os dados juntamente com as TAGS de HTML, e depois salvo essa tStringList em um arquivo .HTML.


GOSTEI 0
Weber

Weber

17/12/2003

procedure TForm1.Button1Click(SEnder: TObject);
var
i, j, w: integer;
linha: string;
htmlfile: TextFile;
const
wrap=#13+10; {estamos declarando esta constante com o valor da tecla enter ...}
begin
AssignFile(HtmlFile, ´c:\htmlfile.html´);
Rewrite(HtmlFile);
writeln(htmlfile, ´<html><head>´ + wrap + {estamos gerando o inicio do arquivo html}
´<title>´+ Table1.name + ´</title>´ + wrap +
´</head>´ + wrap + ´´ +
wrap + ´<table border =1>´ + wrap); {Nesse ponto iremos gerar a tabela html}
with table1 do begin
for w:=0 to fieldCount - 1 do
writeln(htmlfile, ´<td>´ + (Fields[w].FieldName) + ´</td>´);
{Na linha de cima iremos gerar uma coluna em html para cada campo da table 1 com os seus nomes}
table1.first;
for i:=0 to recordcount-1 do
begin
linha:=´<tr>´+wrap;
for j:=0 to fieldcount-1 do
begin
linha:= linha + ´<td>´ + Fields[j].AsString + ´</td>´;
{Este código pega o valor dos campos de cada linha da table e joga na tabela de html}
end;
writeln(htmlfile, linha);
writeln(htmlfile, ´</tr>´);
next;
end;
end;
writeln(htmlfile, ´</html>´); {Finaliza o arquivo html}
CloseFile(htmlfile);
end;


GOSTEI 0
POSTAR