{生成EXCEL文件}
Procedure Putexcel(BQ:TDataSet;
PG:TGauge);
overload;
var
tmpstr:string;
i,j:integer;
app,sheet:variant;
SD:TSaveDialog;
begin
if not bq.Active then
exit;
try
App:=CreateOleObject('Excel.Application');
Sheet:=CreateOleobject('Excel.Sheet');
except
ShowMessage('您的机器里未安装Microsoft Excel!');
exit;
end;
sd:=TSaveDialog.Create(nil);
try
if sd.Execute then
tmpstr:=sd.FileName
else
begin
sheet.close;
App.Quit;
App:=Unassigned;
exit;
end;
sheet:=App.workBooks.Add;
for i:=1 to BQ.FieldCountdo
begin
if bq.Fields[i-1].Tag<>99 then
App.Cells(1 , i):=bq.Fields[i-1].DisplayLabel;
end;
j:=2;
with bqdo
begin
last;
pg.MaxValue:=RecordCount;
first;
while not eofdo
begin
for i:=1 to FieldCountdo
begin
if Fields[i-1].tag<>99 then
begin
if (Fields[i-1].tag=1)and(Fields[i-1].DataType in [ftString,ftWideString]) then
App.Cells(j,i):=''''+Fields[i-1].AsString
else
App.Cells(j,i):=Fields[i-1].AsString;
end;
end;
inc(j);
next;
pg.AddProgress(1);
end;
end;
sheet.saveas(tmpstr);
sheet.close;
App.Quit;
App:=Unassigned;
pg.Progress:=0;
finally
sd.Free;
end;
end;