function isExcelInstalled: olevariant;
var exls
levariant;
begin
try
exls:=createoleobject('Excel.application');
except
application.MessageBox('请先安装MICROSOFT EXCEL!','提示',mb_ok+mb_iconinformation);
exit;
end;
result := exls ;
end;
procedure saveAsExcel(dbgrid: TDBGrid; exls
levariant);
var
fieldNum: integer;
i,j : integer;
sheet: olevariant;
begin
sheet:= exls.workbooks[1].worksheets[1];
with query1 do
begin
DisableControls;
fieldNum := dbgrid.fieldCount;
for i:=1 to fieldNum do
begin
sheet.Cells.Item[1,i]:=Fields[i-1].FieldName;
end;
first;
i:=2;
while not eof do
begin
for j:=1 to fieldNum do
begin
sheet.Cells.Item[i,j]:=fields[j-1].AsString;
end;
next;
inc(i);
end;
EnableControls;
exls.visible:=true;
end;
end;