利用ADOTABLE与ACCESS连接,怎样把EXCELL中的数据全部导入到ACCESS中去?

解决方案 »

  1.   

    不会吧,这个问题就把CSDN难倒了,CSDN没人了?
      

  2.   

    建一个access库,然后用adotable1连excel,adotable2连access库
    adotable1.open;
    adotable2.open;
    adotable2.append;
    while not adotable1.eof then
    begin
      for i:=0 to adotable1.fieldcount-1 do
        adotable2.field[i].value := adotable1.field[i].value;
      adotable2.post; 
      adotable1.next
    end;
      

  3.   

    execltoaccess
      procedure ExportToExcel(Dataset:TDataset);
    var
        Range,WorkBook,Sheet,Excel:variant;
        CurCol,col,row:integer;
        FrmWait:TFrmWait;
    begin
    Excel:=CreateOleObject('Excel.Application');
    FrmWait:=TFrmWait.Create(application);
    try
         FrmWait.Show;
    //     Excel.visible:=true;
         Application.ProcessMessages;
         Excel.DisplayAlerts:=false;
         Excel.WorkBooks.Add;
         WorkBook:=Excel.WorkBooks[1];
         Sheet := WorkBook.WorkSheets[1];
         CurCol:=0;
         Row:=4; //?第四行,第二列?始?出
         for col:=1 to DataSet.FieldCount do //?出??
            if DataSet.Fields[Col-1].Visible then
             begin
               Sheet.Cells[Row,CurCol+2]:=DataSet.Fields[Col-1].DisplayLabel;
               inc(CurCol);
             end;
         inc(Row); //?据?第五行?始?出     DataSet.DisableControls;
         FrmWait.ProgressBar1.Max:=TDataQuery(DataSet).FilterRows;
         FrmWait.Label2.Caption:=format('估?用?:%f 秒',[FrmWait.ProgressBar1.Max/40]);
         DataSet.First;
         while not Dataset.Eof do
           begin
             CurCol:=0;
             for Col:=1 to DataSet.FieldCount do
               if DataSet.Fields[Col-1].Visible then
                 begin
                   Sheet.Cells[Row,CurCol+2]:=DataSet.Fields[Col-1].DisplayText;
                   inc(CurCol);
                 end;
             DataSet.Next;
             inc(Row);
             FrmWait.ProgressBar1.Position:=Row;
             FrmWait.Label2.Caption:=format('估?用?:%f 秒',[(FrmWait.ProgressBar1.Max-FrmWait.ProgressBar1.Position)/40]);
             if FrmWait.ConFirmQuit then
              if YesNoBox('确定要取消?前操作??') then
               begin
                 Dataset.EnableControls;
                 Excel.quit;
                 exit;
               end else FrmWait.ConFirmQuit:=false;
             Application.ProcessMessages;
           end;     Range:=Sheet.Range['1:65536'];
         Range.Verticalalignment:= -4108;//Center; //垂直中??
         //???表格?的范?
         Range:=Sheet.Range[Sheet.cells[4,2].Address+':'
                    +Sheet.cells[Row-1,CurCol+1].Address];
         Range.Borders.LineStyle:=1;
         Range.Font.Name:='宋体';  //?置字体和大小
         Range.Font.Size:=11;     Sheet.Cells.Columns.AutoFit; //自??整列?
         Excel.visible:=true;
    {     try
           Sheet.PrintPreView;
         finally
           Excel.quit;
         end;
    }
    finally
        FrmWait.Free;
        Dataset.EnableControls;
    end;
    end;