新建一个窗体加一个TIMER控件,将下面的代码加入你的TIMER控件,也许有用.
var
I,n,J,M,K:integer;
begin
TIMER1.Enabled:=FALSE;
try
oleobject := CreateOleObject('EXCEL.APPLICATION');
except
MessageBeep(0);
Application.MessageBox('您的系统未安装 MS EXCEL或EXCEL错误!','提示信息',16);
Exit;
end;
oleOBJECT.WORKBOOKS.ADD;
N:=SENDQUERY.RecordCount;
M:=SENDQUERY.FieldCount-1;
SENDQUERY.First;
SENDQuery.DisableControls;
LABEL1.Caption:='正在发送数据...';
LABEL1.Refresh;
try
FOR J:=0 TO Mdo
begin
IF ISCANCEL then
begin
IF APPLICATION.MessageBox('真的要终止数据发送吗?','请确认',36)=6 then
begin
OLEOBJECT.DISPLAYALERTS:=FALSE;
OLEOBJECT.quit;
close;
EXIT;
END
else
ISCANCEL:=FALSE;
end;
APPLICATION.ProcessMessages;
OLEOBJECT.WORKBOOKS[1].WORKSHEETS[1].CELLS[1,J+1].VALUE:=
TRIM(SENDQUERY.FIELDS[J].FIELDNAME);
end;
FOR I:=1 TO Ndo
begin
K:=ROUND(100*I/N);
PROBAR.POSITION:=K;
LABEL2.Caption:='已完成'+trim(inttostr(k))+'%';
LABEL2.Refresh;
FOR J:=0 TO Mdo
begin
IF ISCANCEL then
begin
IF APPLICATION.MessageBox('真的要终止数据发送吗?','请确认',36)=6 then
begin
OLEOBJECT.DISPLAYALERTS:=FALSE;
OLEOBJECT.quit;
close;
EXIT;
END
else
ISCANCEL:=FALSE;
end;
APPLICATION.ProcessMessages;
OLEOBJECT.WORKBOOKS[1].WORKSHEETS[1].CELLS[I+1,J+1].VALUE:=
TRIM(SENDQUERY.Fields[J].ASSTRING);
end;
SENDQUERY.NEXT;
end;
except
messageBeep(0);
Application.MessageBox('发送数据失败!','提示信息',64);
OLEOBJECT.DISPLAYALERTS:=FALSE;
OLEOBJECT.quit;
CLOSE;
exit;
end;
SENDQUERY.EnableControls;
OLEOBJECT.VISIBLE:=TRUE;
CLOSE;