grid.datasource.dataset.first;
grid.datasource.dataset.moveby(ncurrentcount);
if ntotalcount-ncurrentcount>xls.maxrows then nonesheetmaxrecord := xls.maxrows
else nonesheetmaxrecord := ntotalcount-ncurrentcount;
for i:=0 to nonesheetmaxrecord-1 do
begin
application.processmessages;
inc(ncurrentcount);
callfunc(ncurrentcount/ntotalcount);
if g_usercmd=userstop then
begin
if baskforstop then
case application.messagebox('您停止了导出数据,请问需要保存吗?(选择“取消”继续导出)','询问',mb_yesnocancel) of
idyes:begin
g_usercmd := userneedsave;
break;
end;
idno: begin
g_usercmd := usernotsave;
bdontsave := true;
raise exception.create('用户停止,导出数据未保存!');
end;
idcancel: g_usercmd := userdonothing;
end
else begin bdontsave := true; raise exception.create('用户停止,导出数据未保存!'); end;
end;
for c:=0 to grid.fieldcount-1 do
if (grid.fields[c].asstring<>'') then
xls.writefield(r,c,grid.fields[c]);
inc(r);
grid.datasource.dataset.next;
end;
xls.writeeof;
finally
xls.free;
end;
bnoteof := (not grid.datasource.dataset.eof) and (g_usercmd = userdonothing);
end; //not grid.datasource.dataset.eof
finally
if bdontsave then
for i:=1 to result do deletefile(path+'\$$$'+inttostr(i)+filename);
grid.datasource.dataset.enablecontrols;
end;
if bneedunite and (not bdontsave) then
begin
if result=1 then
begin
deletefile(fname);
renamefile(tmpfile, fname)
end
else
begin
with tuniteseveralxlstoonethread.create('$$$', path, filename, 1, result) do
begin
while not mcompleted do
begin
application.processmessages;
sleep(0);
end;
end;
for i:=1 to result do deletefile(path+'\$$$'+inttostr(i)+filename);
end;
end;