我用的是access2000数据库delphi的ado连接!请问我怎么样才能将数据表中的数据导入到excel中请详细指教!最好给个简单的例子!谢谢!

解决方案 »

  1.   

    http://expert.csdn.net/Expert/TopicView1.asp?id=1909498
      

  2.   

    //转帖自中文开发在线
    var  
      I: Integer;  
      Str: String;  
      StrList: TStringList;//用于存储数据的字符列表
    begin  
      StrList := TStringList.Create;  
      try    
        with Table1 do    
        begin      
          First;      
          while not Eof do      
          begin      
            Str := '';        
            for I := 0 to FieldCount-1 do      
              Str := Str + Fields[I].AsString + #9;  
            StrList.Add(Str);        
            Next;      
          end;      
          StrList.SaveToFile('test.xls');    
        end;    
      finally    
        StrList.Free;  
      end;
    end;
      

  3.   

    http://www.codelphi.com/channel/jsjn/read.asp?ano=712
      

  4.   

    函数名称:
    Function DataSetToExcel(
      DataSet:TDataSet;FieldTagMax:Integer;
      Visible:Boolean;ExcelFileName:String=''): Boolean;
    实现:Function DataSetToExcelSheet(DataSet:TDataSet;FieldTagMax:Integer;Sheet:OleVariant): Boolean;
    var
      Row,Col,FieldIndex :Integer;
      BK:TBookMark;
    begin
      Result := False;
      if not Dataset.Active then exit;
      BK:=DataSet.GetBookMark;
      DataSet.DisableControls;
      Sheet.Activate;
      try
        // 列标题
        Row:=1;
        Col:=1;
        for FieldIndex:=0 to DataSet.FieldCount-1 do
        begin
          if DataSet.Fields[FieldIndex].Tag <= FieldTagMax then
          begin
            Sheet.Cells(Row,Col) :=DataSet.Fields[FieldIndex].DisplayLabel;
            Inc(Col);
          end;
        end;
        // 表内容
        DataSet.First;
        while Not DataSet.Eof do
        begin
          Row:=Row+1;
          Col:=1;
          for FieldIndex:=0 to DataSet.FieldCount-1 do
          begin
            if DataSet.Fields[FieldIndex].Tag <= FieldTagMax then
            begin
              Sheet.Cells(Row,Col):=DataSet.Fields[FieldIndex].AsString;
              Inc(Col);
            end;
          end;
          DataSet.Next;
        end;
        Result := True;
      finally
        DataSet.GotoBookMark(BK);
        DataSet.EnableControls;
      end;
    end;Function DataSetToExcel(
      DataSet:TDataSet;FieldTagMax:Integer;
      Visible:Boolean;ExcelFileName:String=''): Boolean;
    var
      ExcelObj, Excel, WorkBook, Sheet: OleVariant;
      OldCursor:TCursor;
      SaveDialog:TSaveDialog;
    begin
      Result := False;
      if not Dataset.Active then exit;  OldCursor:=Screen.Cursor;
      Screen.Cursor:=crHourGlass;  try
        ExcelObj := CreateOleObject('Excel.Sheet');
        Excel := ExcelObj.Application;
        Excel.Visible := Visible ;
        WorkBook := Excel.Workbooks.Add ;
        Sheet:= WorkBook.Sheets[1];
      except
        MessageBox(GetActiveWindow,'无法调用Mircorsoft Excel! '+chr(13)+chr(10)+
        '请检查是否安装了Mircorsoft Excel。','提示',MB_OK+MB_ICONINFORMATION);
        Screen.Cursor:=OldCursor;
        Exit;
      end;  Result:=DataSetToExcelSheet(DataSet,FieldTagMax,Sheet) ;
      if Result then
        if Not Visible then
        begin
          if ExcelFileName<>'' then
            WorkBook.SaveAs(FileName:=ExcelFileName)
          else begin
            SaveDialog:=TSaveDialog.Create(Nil);
            SaveDialog.Filter := 'Microsoft Excel 文件|*.xls';
            Result:=SaveDialog.Execute;
            UpdateWindow(GetActiveWindow);
            if Result then
              WorkBook.SaveAs(FileName:=SaveDialog.FileName);
            SaveDialog.Free;
          end;
          Excel.Quit;
        end;
      Screen.Cursor:=OldCursor;
    end;
      

  5.   

    用ADO没有这么复杂的
    发你的EMAIL ADDRES TO THIS ADDRES:
        [email protected]
    I HAVE A ESSY CODE!