whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1547)

Database (90)
Files (137)
Forms (107)
Graphic (115)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Math (76)
Misc (127)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

32 Visitors Online


 
...save a TListView as an HTML page?
Autor: Robert Muth
[ Print tip ]  

Tip Rating (8):  
     


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;




 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners