; 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;
finally
xls.writeeof;
xls.free;
if bdontsave then deletefile(fname);
grid.datasource.dataset.enablecontrols;
g_xlswriterisruning := false;
end;
end;
//将数个xls合并成一个(分页)
procedure uniteseveralxlstoone(const tmpflag, path, filename : string;const istart, iend : integer);
const
_headletterofxls:array [1..52]of string
= ('a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z',
'aa','ab','ac','ad','ae','af','ag','ah','ai','aj','ak','al','am',
'an','ao','ap','aq','ar','as','at','au','av','aw','ax','ay','az');
_xlsrescaption= 'fkulwjs_sksla_892x_res';
_xlstmpcaption= 'fkulwjs_sksla_892x_tmp';
var
xlsappres, xlsapptmp: texcelapplication;
wkbookres, wkbooktmp : _workbook;
wksheetres, wksheettmp : _worksheet;
lcid_res, lcid_tmp:integer;
pos_lefttop, pos_rightbottom : string; //xls中左上、右下位置
xlsapphwnd:thandle;
bdontsave : boolean;
i : integer;
strname,strext:string; //文件名及扩展名
begin
splitstrtotwopartbylastflag(filename, '.', strname, strext);
try
bdontsave := false;
xlsappres := texcelapplication.create(nil);
with xlsappres do
begin
connect;
visible[0]:=false;
lcid_res:=getuserdefaultlcid();
displayalerts[lcid_res]:=false;
caption:=_xlsrescaption;
wkbookres:=workbooks.add(emptyparam,lcid_res);
end;
xlsapptmp := texcelapplication.create(nil);
with xlsapptmp do
begin
connect;
visible[0]:=false;
lcid_tmp :=getuserdefaultlcid();
displayalerts[lcid_tmp]:=false;
caption:=_xlstmpcaption;
end;
for i:=istart to iend do
begin
if i<=3 then wksheetres:=wkbookres.sheets[i] as _worksheet
else
begin
wkbookres.sheets.add(emptyparam, wksheetres, 1, emptyparam, lcid_res);
wksheetres := wkbookres.sheets[i] as _worksheet;
end;
wkbooktmp:= xlsapptmp.workbooks.open(path+'\'+tmpflag+inttostr(i)+filename, emptyparam,emptyparam,
emptyparam,emptyparam,emptyparam,emptyparam,
emptyparam,emptyparam,emptyparam,emptyparam,
emptyparam,emptyparam,lcid_tmp);
pos_lefttop := 'a1';
wksheettmp := xlsapptmp.activesheet as _worksheet;
pos_rightbottom := _headletterofxls[wksheettmp.usedrange[lcid_tmp].columns.count]+inttostr(wksheettmp.usedrange[lcid_tmp].rows.count);
xlsapptmp.range[pos_lefttop, pos_rightbottom].copy(