var myExcel:Variant; i,j:integer; begin try myExcel:=createOleObject('Excel.application'); myExcel.Visible:=True; myExcel.WorkBooks.add;for i:=0 to listview1.Columns.Count-1 do myExcel.workSheets[1].Cells[1,i+1].Value:=''''+listview1.Column[i].Caption;if listview1.Items.Count>0 then for j:=0 to listview1.Items.Count-1 do begin for i:=0 to listview1.Columns.Count-1 do if i=0 then myExcel.workSheets[1].Cells[j+2,i+1].Value:=trim(listview1.Items[j].Caption) else myExcel.workSheets[1].Cells[j+2,i+1].Value:=trim(listview1.Items[j].SubItems[i-1]); end; except Messagedlg('Export Error!',mtWarning,[mbOK],1); end; end;
myExcel:Variant;
i,j:integer;
begin
try
myExcel:=createOleObject('Excel.application');
myExcel.Visible:=True;
myExcel.WorkBooks.add;for i:=0 to listview1.Columns.Count-1 do
myExcel.workSheets[1].Cells[1,i+1].Value:=''''+listview1.Column[i].Caption;if listview1.Items.Count>0 then
for j:=0 to listview1.Items.Count-1 do
begin
for i:=0 to listview1.Columns.Count-1 do
if i=0 then
myExcel.workSheets[1].Cells[j+2,i+1].Value:=trim(listview1.Items[j].Caption)
else
myExcel.workSheets[1].Cells[j+2,i+1].Value:=trim(listview1.Items[j].SubItems[i-1]);
end;
except
Messagedlg('Export Error!',mtWarning,[mbOK],1);
end;
end;