if (SHFileOperation(opinfo)<>0) then
begin
ShowMessage('Îļþ²Ù×÷ʧ°Ü£¬ÏµÍ³½«Í˳ö£¡');
exit;
end;
////////////////////////////////////////////////////////////////
try
ea.Connect;
except
end;
ea.Visible[0]:=false;
eb.ConnectTo(ea.Workbooks.Open(dfn,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,0));
ew.ConnectTo(eb.activesheet as _worksheet);
rs:=Tquery.Create(application);
rs.databasename :='cnqf';
if ((frmlogin.varqxinfo.dhhb=0) and(frmlogin.varqxinfo.dhzs=0) and (frmlogin.varqxinfo.xhhb=0) and(frmlogin.varqxinfo.xhzs=0) and(frmlogin.varqxinfo.xtgly=1)and(frmlogin.varqxinfo.leader=0))or ((frmlogin.varqxinfo.xhcx=0) and (frmlogin.varqxinfo.dhcx=0))then
begin
if checkbox1.Checked and checkbox2.Checked and checkbox4.Checked then
begin
str:='select qfxx.hh,qfxx.hm,yhda.dz,qfxx.dfyf,qfxx.sjje from qfxx,yhda where (yhda.hh=qfxx.hh) and (yhda.bmbs='+''''+combo_bmbs.text+''''+')and (qfxx.dfyf>='+''''+formatDateTime('yyyy-mm',DateTimePicker1.Date)+''''+' and qfxx.dfyf<='+''''+FormatDateTime('yyyy-mm',DateTimePicker2.Date)+''''+') and (qfxx.xzdjsj>='+''''+formatDateTime('yyyy-mm-dd',DateTimePicker3.Date)+''''+' and qfxx.xzdjsj<='+''''+FormatDateTime('yyyy-mm-dd',DateTimePicker4.Date)+''''+')';
rs.Active:=false;
rs.SQL.Clear;
rs.SQL.Add(str);
rs.Active:=true;
///////////////////////////////////////////////////////////////////
rs.DisableControls;
i:=2;
while not rs.eof do
begin
stmp:=rs.fieldbyname('hh').AsString;
ew.Cells.Item[i,1]:=stmp ;
ew.Cells.Item[i,2]:=rs.fieldbyname('hm').AsString;
ew.Cells.Item[i,3]:=rs.fieldbyname('dz').AsString;
ew.Cells.Item[i,4]:=rs.fieldbyname('dfyf').AsString;
ew.Cells.Item[i,5]:=rs.fieldbyname('sjje').AsString;
i:=i+1;
rs.Next;
end;
rs.EnableControls;
rs.Close;
rs.Destroy;
ea.DisplayFullScreen[0]:=true;
ea.DisplayFullScreen[0]:=false;
ea.Visible[0]:=true;
end;
if (frmlogin.varqxinfo.dhhb=1) or (frmlogin.varqxinfo.dhzs=1)then
begin
str:='select qfxx.hh,qfxx.hm,yhda.dz,qfxx.dfyf,qfxx.hdf from qfxx,yhda where (yhda.hh=qfxx.hh) and (yhda.bmbs='+''''+combo_bmbs.Text+''''+') and (qfxx.dfyf>='+''''+formatDateTime('yyyy-mm',DateTimePicker1.Date)+''''+' and qfxx.dfyf<='+''''+FormatDateTime('yyyy-mm',DateTimePicker2.Date)+''''+') and ((qfxx.xzdjsj<='+''''+formatDateTime('yyyy-mm-dd',DateTimePicker5.Date)+''''+') ) and (qfxx.xzbz='+''''+'δÏúÕÊ'+''''+')';
rs.Active:=false;
rs.SQL.Clear;
rs.SQL.Add(str);
rs.Active:=true;
///////////////////////////////////////////////////////////////////
rs.DisableControls;
i:=2;
while not rs.eof do
begin
stmp:=rs.fieldbyname('hh').AsString;
ew.Cells.Item[i,1]:=stmp ;
ew.Cells.Item[i,2]:=rs.fieldbyname('hm').AsString;
ew.Cells.Item[i,3]:=rs.fieldbyname('dz').AsString;
ew.Cells.Item[i,4]:=rs.fieldbyname('dfyf').AsString;
ew.Cells.Item[i,5]:=rs.fieldbyname('hdf').AsString;
i:=i+1;
rs.Next;
end;
这是我的一些代码,请看看我的问题,为什么这么慢?
if (SHFileOperation(opinfo)<>0) then
begin
ShowMessage('Îļþ²Ù×÷ʧ°Ü£¬ÏµÍ³½«Í˳ö£¡');
exit;
end;
////////////////////////////////////////////////////////////////
try
ea.Connect;
except
end;
ea.Visible[0]:=false;
eb.ConnectTo(ea.Workbooks.Open(dfn,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,emptyparam,0));
ew.ConnectTo(eb.activesheet as _worksheet);
rs:=Tquery.Create(application);
rs.databasename :='cnqf';
if ((frmlogin.varqxinfo.dhhb=0) and(frmlogin.varqxinfo.dhzs=0) and (frmlogin.varqxinfo.xhhb=0) and(frmlogin.varqxinfo.xhzs=0) and(frmlogin.varqxinfo.xtgly=1)and(frmlogin.varqxinfo.leader=0))or ((frmlogin.varqxinfo.xhcx=0) and (frmlogin.varqxinfo.dhcx=0))then
begin
if checkbox1.Checked and checkbox2.Checked and checkbox4.Checked then
begin
str:='select qfxx.hh,qfxx.hm,yhda.dz,qfxx.dfyf,qfxx.sjje from qfxx,yhda where (yhda.hh=qfxx.hh) and (yhda.bmbs='+''''+combo_bmbs.text+''''+')and (qfxx.dfyf>='+''''+formatDateTime('yyyy-mm',DateTimePicker1.Date)+''''+' and qfxx.dfyf<='+''''+FormatDateTime('yyyy-mm',DateTimePicker2.Date)+''''+') and (qfxx.xzdjsj>='+''''+formatDateTime('yyyy-mm-dd',DateTimePicker3.Date)+''''+' and qfxx.xzdjsj<='+''''+FormatDateTime('yyyy-mm-dd',DateTimePicker4.Date)+''''+')';
rs.Active:=false;
rs.SQL.Clear;
rs.SQL.Add(str);
rs.Active:=true;
///////////////////////////////////////////////////////////////////
rs.DisableControls;
i:=2;
while not rs.eof do
begin
stmp:=rs.fieldbyname('hh').AsString;
ew.Cells.Item[i,1]:=stmp ;
ew.Cells.Item[i,2]:=rs.fieldbyname('hm').AsString;
ew.Cells.Item[i,3]:=rs.fieldbyname('dz').AsString;
ew.Cells.Item[i,4]:=rs.fieldbyname('dfyf').AsString;
ew.Cells.Item[i,5]:=rs.fieldbyname('sjje').AsString;
i:=i+1;
rs.Next;
end;
rs.EnableControls;
rs.Close;
rs.Destroy;
ea.DisplayFullScreen[0]:=true;
ea.DisplayFullScreen[0]:=false;
ea.Visible[0]:=true;
end;
if (frmlogin.varqxinfo.dhhb=1) or (frmlogin.varqxinfo.dhzs=1)then
begin
str:='select qfxx.hh,qfxx.hm,yhda.dz,qfxx.dfyf,qfxx.hdf from qfxx,yhda where (yhda.hh=qfxx.hh) and (yhda.bmbs='+''''+combo_bmbs.Text+''''+') and (qfxx.dfyf>='+''''+formatDateTime('yyyy-mm',DateTimePicker1.Date)+''''+' and qfxx.dfyf<='+''''+FormatDateTime('yyyy-mm',DateTimePicker2.Date)+''''+') and ((qfxx.xzdjsj<='+''''+formatDateTime('yyyy-mm-dd',DateTimePicker5.Date)+''''+') ) and (qfxx.xzbz='+''''+'δÏúÕÊ'+''''+')';
rs.Active:=false;
rs.SQL.Clear;
rs.SQL.Add(str);
rs.Active:=true;
///////////////////////////////////////////////////////////////////
rs.DisableControls;
i:=2;
while not rs.eof do
begin
stmp:=rs.fieldbyname('hh').AsString;
ew.Cells.Item[i,1]:=stmp ;
ew.Cells.Item[i,2]:=rs.fieldbyname('hm').AsString;
ew.Cells.Item[i,3]:=rs.fieldbyname('dz').AsString;
ew.Cells.Item[i,4]:=rs.fieldbyname('dfyf').AsString;
ew.Cells.Item[i,5]:=rs.fieldbyname('hdf').AsString;
i:=i+1;
rs.Next;
end;
这是我的一些代码,请帮忙看看问题
//过程
procedure toxls(title:string;sqlstr:string;fname:string);
var
i,j:integer;
mem:tmemo;
str:string;
eclApp,WorkBook:Variant;
//声明为OLE Automation 对象
xlsFileName:string;
begin
with DM1.ADOQ_xls do
begin
close;
sql.clear;
sql.add(sqlstr);
open;
end;
try
//创建OLE对象Excel Application与 WorkBook
eclApp:=CreateOleObject('Excel.Application');
WorkBook:=CreateOleobject('Excel.Sheet');
except
application.MessageBox(pchar('您的机器里未安装 Microsoft Excel 。'),'提示信息',MB_ICONinformation+mb_ok);
Exit;
end;
try
workBook:=eclApp.workBooks.Add;
//显示表头
for j:=1 to DM1.ADOQ_xls.FieldCount do
eclApp.Cells(1,j):=FindStr(title,j);
//确定内容
DM1.ADOQ_xls.first;
while not DM1.ADOQ_xls.eof do
begin
for j:=0 to DM1.ADOQ_xls.FieldCount-1 do
begin
//if DM1.ADOQ_xls.Fields[j].DataType<>ftString then
// eclApp.Cells(DM1.ADOQ_xls.RecNo+1,j+1).type:='数值型'
//else
// eclApp.Cells(DM1.ADOQ_xls.RecNo+1,j+1).type:='文本格式';
eclApp.Cells(DM1.ADOQ_xls.RecNo+1,j+1):=dm1.ADOQ_xls.Fields[j].asstring;
end;
DM1.ADOQ_xls.next;
end;
fmain.s1.filename:=fname;
if not fmain.s1.execute then
exit;
WorkBook.saveas(fmain.s1.filename);
WorkBook.close;
eclApp.Quit;
//退出Excel Application
//释放VARIANT变量
eclApp:=Unassigned;
application.MessageBox(pchar('文件保存成功!'),'提示信息',MB_ICONinformation+mb_ok);
except
ShowMessage('不能正确操作Excel文件。可能是该文件已被其他程序打开, 或系统错误。');
WorkBook.close;
eclApp.Quit;
//释放VARIANT变量
eclApp:=Unassigned;
end;
end;