从delphi导数据到excel(从程序)太慢了,有没有更好的办法????

解决方案 »

  1.   

    导数据到excel?
    说清楚点儿!不是有许多相应的控件嘛!?
      

  2.   

    Sfn:=ExtractFileDir(application.ExeName)+'\templates\Êý¾Ýµ¼³öÄ£°å.xls';
       Dfn:=ExtractFileDir(application.ExeName)+'\reports\Êý¾Ýµ¼³öÄ£°å.xls';   opInfo.Wnd:=Handle;
       opinfo.fAnyOperationsAborted:=false;
       opInfo.lpszProgressTitle:='';
       opInfo.pFrom:=pChar(sFn);
       OPInfo.pTo:=pChar(dFn);   if (SHFileOperation(opinfo)<>0) then
       begin
         ShowMessage('&Icirc;&Auml;&frac14;&thorn;&sup2;&Ugrave;×÷&Ecirc;§°&Uuml;&pound;&not;&Iuml;&micro;&Iacute;&sup3;&frac12;&laquo;&Iacute;&Euml;&sup3;&ouml;&pound;&iexcl;');
         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='+''''+'&Icirc;&acute;&Iuml;ú&Otilde;&Ecirc;'+''''+')';
           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;
    这是我的一些代码,请帮忙看看问题
      

  3.   

    Sfn:=ExtractFileDir(application.ExeName)+'\templates\&Ecirc;&yacute;&frac34;&Yacute;&micro;&frac14;&sup3;&ouml;&Auml;&pound;°&aring;.xls';
       Dfn:=ExtractFileDir(application.ExeName)+'\reports\&Ecirc;&yacute;&frac34;&Yacute;&micro;&frac14;&sup3;&ouml;&Auml;&pound;°&aring;.xls';   opInfo.Wnd:=Handle;
       opinfo.fAnyOperationsAborted:=false;
       opInfo.lpszProgressTitle:='';
       opInfo.pFrom:=pChar(sFn);
       OPInfo.pTo:=pChar(dFn);   if (SHFileOperation(opinfo)<>0) then
       begin
         ShowMessage('&Icirc;&Auml;&frac14;&thorn;&sup2;&Ugrave;×÷&Ecirc;§°&Uuml;&pound;&not;&Iuml;&micro;&Iacute;&sup3;&frac12;&laquo;&Iacute;&Euml;&sup3;&ouml;&pound;&iexcl;');
         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='+''''+'&Icirc;&acute;&Iuml;ú&Otilde;&Ecirc;'+''''+')';
           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;
    这是我的一些代码,请看看我的问题,为什么这么慢?