Сохранить TListView как HTML страницу
Материал из DRKB
Сохранить TListView как HTML страницу[править | править код]
function ListViewConfHTML(listview: TListview; output: string; center: Boolean): Boolean;
var
i, f: Integer;
tfile: TextFile;
begin
try
ForceDirectories(ExtractFilePath(output));
AssignFile(tfile, output);
ReWrite(tfile);
WriteLn(tfile, '<html>');
WriteLn(tfile, '<head>');
WriteLn(tfile, '<title>HTML-Ansicht: ' + listview.Name + '</title>');
WriteLn(tfile, '</head>');
WriteLn(tfile, '<table border="1" bordercolor="#000000">');
WriteLn(tfile, '<tr>');
for i := 0 to listview.Columns.Count - 1 do
begin
if center then
WriteLn(tfile, '<td><b><center>' + listview.Columns[i].Caption + '</center></b></td>')
else
WriteLn(tfile, '<td><b>' + listview.Columns[i].Caption + '</b></td>');
end;
WriteLn(tfile, '</tr>');
WriteLn(tfile, '<tr>');
for i := 0 to listview.Items.Count-1 do
begin
WriteLn(tfile, '<td>' + listview.Items.Item[i].Caption + '</td>');
for f := 0 to listview.Columns.Count-2 do
begin
if listview.Items.Item[i].Subitems[f] = '' then
Write(tfile, '<td>-</td>')
else
Write(tfile, '<td>' + listview.Items.Item[i].Subitems[f] + '</td>');
end;
Write(tfile, '</tr>');
end;
WriteLn(tfile, '</table>');
WriteLn(tfile, '</html>');
CloseFile(tfile);
Result := True;
except
Result := False;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if ListViewConfHTML(form1.ListView1, 'C:\text.html', true) then
ShowMessage('OK/ Hat geklappt')
else
ShowMessage('Error occured/ Hat nicht geklappt');
end;
Source: Взято с сайта: http://www.swissdelphicenter.ch
ID: 01149