procedure Tfmxinmingxi.bitbtnClick(Sender: TObject);
var
row,col,j,i:integer;
sheet:variant;
begin
if messagedlg('导出数据过程中可能需要一段时间'+#13+'是否继续?',mtinformation,[mbyes,mbno],0)=mryes then
begin
fmcenter.Queryxjbtotal.DisableControls;
cursor:=loadcursorfromfile(pchar(curpath));
setclasslong(dbgrid1.handle,GCL_HCURSOR,cursor);
setclasslong(panel1.handle,GCL_HCURSOR,cursor);
fmxinmingxi.update;
try
col:=0;
exele:=createoleobject('excel.application');
exele.workbooks.add(xlwbatworksheet);
exele.worksheets[1].name:='现金收付明细表';
sheet:=exele.workbooks[1].worksheets['现金收付明细表'];
for j:=0 to dbgrid1.FieldCount-1do
if dbgrid1.Columns[j].visible then
begin
sheet.cells[1,col+1]:=dbgrid1.Columns[j].Title.Caption;
inc(col);
end;
i:=2;
fmcenter.Queryxjbtotal.First;
ProgressBar1.visible:=true;
ProgressBar1.max:=fmcenter.queryxjbtotal.recordcount;
while not fmcenter.Queryxjbtotal.eofdo
begin
col:=0;
for j:=0 to dbgrid1.FieldCount-1do
if dbgrid1.Columns[j].Visible then
begin
sheet.cells[i,col+1]:=dbgrid1.Fields[j].Asstring;
inc(col);
end;
inc(i);
ProgressBar1.StepBy(i);
fmcenter.Queryxjbtotal.Next;
end;
ProgressBar1.position:=0;
ProgressBar1.visible:=false;
exele.visible:=true;
except
exele.quit;
showmessage('输出数据过程中出现错误');
end;
end;
setclasslong(dbgrid1.handle,GCL_HCURSOR,cur);
setclasslong(panel1.handle,GCL_HCURSOR,cur);
fmcenter.Queryxjbtotal.EnableControls;
end;