在access表我对需要的数据部分选定,然后复制,在excel中在选定的区域
粘贴。可以。
其它的数据表,你照此试一试。

解决方案 »

  1.   

    找个控件喽。
    要自己写,一句话好像说不完,涉及COM。
    可以到已解决区找一找,应该有的。
      

  2.   

    在use 中加上ComObj然后就这么几句就可以了:
    ...
    Var
       Sheet,ExcelApp:Variant;
    begin
     ExcelApp:=CreateOleObject('Excel.Application');
     ExcelApp.Visible:=True;
     ExcelApp.workbooks.add(GetCurrentDir() + '\' + 'Demo.xls'); //一般都是在一个模板文件里写数据
     Sheet:=ExcelApp.workbooks[1].worksheets[1];
       Sheet.cells[25,4].Value := 'Hello,Excel!';
    end;
      

  3.   

    procedure TForm.Excel_BtnClick(Sender: TObject);
    var
     Excel,WorkBook, Sheet:variant;
     Col, Row,iRow : Integer;
     s:string;
    begin
      If Application.MessageBox('导入Excel?','系统提示',MB_OKCANCEL + 32)<>IDOk then Exit;
      try
        Excel:= Unassigned;
        Excel:=GetActiveOleObject('Excel.Application');
      except
       Try
         Excel:=UnAssigned;
         Excel:=CreateOleObject('Excel.Application');
       Except
         Application.MessageBox(请确认是否正确安装Excel!','系统提示',MB_OK + 48);
       end;
     end;
      Excel.Visible:=True;
      Excel.DisplayAlerts:=false;
      Excel.WorkBooks.Add;
      Excel.SheetsInNewWorkbook := 1;
      WorkBook := Excel.WorkBooks.Add;
      Sheet := WorkBook.WorkSheets[1];
      Sheet.Name:=Caption;
      Row := 2;
      Sheet.Rows[Row].Font.Bold := True;
      inc(Row,2);
      Sheet.Rows[Row].Font.Bold := True;
      with DataSource1.Dataset do begin
        for Col := 0 to FieldCount-1 do
          if Fields[col].visible = True then
          Sheet.Cells[Row, Col+1] := Fields[col].DisplayName;
        inc(Row);
        First;
        while not Eof do begin
          for Col := 0 to FieldCount-1 do begin
            if Fields[col].visible = false then continue;
            s:=' '+Fields[col].AsString;
            Sheet.Cells[Row, Col+1]:=s;
          end;
          Inc(Row);
          next;
        end;
      end;
      Sheet.Cells.Columns.AutoFit;
      Sheet.Cells[2, 2] := Main_Screen.Company_Name + '  '+Caption;
    end;
      

  4.   

    var
      MSExcel:Variant;
      i,j:integer;
    begin
     SaveDialog1.Filter:='*.XLS|*.XLS';
    SaveDialog1.DefaultExt:='XLS';
    if SaveDialog1.Execute then
    begin
      MsExcel:=createOLEobject('excel.application');
      MsExcel.workBooks.add;
      Msexcel.visible:=false;
      with dm.adchaxun do
      begin
       first;
       for i:=0 to fieldcount-1 do
       begin
        Msexcel.cells[1,i+1].value:=fields[i].DisplayLabel ;
        end;
        j:=2;
        while not eof do
        begin
          for i:=0 to fieldcount-1 do
          begin
            Msexcel.cells[j,i+1].numberformat:='@';
            Msexcel.cells[j,i+1].value:=fields[i].AsString ;
            end;
            inc(j);
            next;
          end;
          end;
           MSExcel.ActiveWorkBook.SaveAs(SaveDialog1.FileName);
           MSExcel.ActiveWorkBook.Saved:=True;
           MSExcel.Quit;
      end;
      end;
      

  5.   

    用ADO来保存为EXCEL文件不就行了吗