copy from advlistview
procedure TAdvListView.SavetoXLS(filename:string);
var
fexcel:variant;
fworkbook:variant;
fworksheet:variant;
farray:variant;
s,z:integer;
rangestr:string[12];
lis:tlistitem;
begin
screen.cursor:=crHourGlass;
try
FExcel:=CreateOleObject('excel.application');
except
screen.cursor:=crDefault;
raise EAdvListViewError.Create('Excel OLE server not found');
exit;
end;
FWorkBook := FExcel.WorkBooks.Add;
FWorkSheet := FWorkBook.WorkSheets.Add;
farray:=vararraycreate([0,self.items.count-1,0,self.columns.count-1],varVariant);
for s:=0 to self.items.count-1 do
begin
lis:=self.items;
for z:=0 to self.columns.count-1 do
begin
if z=0 then farray[s,z]:=lis.caption
else
begin
if z-1>=lis.subitems.Count then
farray[s,z]:=''
else
farray[s,z]:=lis.subitems[z-1];
end;
end;
end;
rangestr:='A1:';
if (self.Columns.count>26) then
begin
rangestr:=rangestr+chr(ord('A')-1+(self.columns.count div 26));
rangestr:=rangestr+chr(ord('A')-1+(self.columns.count mod 26));
end
else
rangestr:=rangestr+chr(ord('A')-1+self.columns.count);
rangestr:=rangestr+inttostr(self.items.count);
FWorkSheet.Range[rangestr].Value:=fArray;
FWorkbook.SaveAs(filename);
FExcel.Quit;
FExcel:=unassigned;
screen.cursor:=crDefault;
end;