怎样在delphi中把资料导入到excel中去啊?

解决方案 »

  1.   

    在论坛里面搜索一下,关键字为excel,帖子很多的
      

  2.   

    procedure TfrmSG.Button1Click(Sender: TObject);  uses ComObj
    var
      pc_i:integer;
      xlapp,sheet: variant;
      WBK: OleVariant;
    begin
      xlapp := createoleobject('excel.application');
      if Trim(Edit1.Text)='' then
      begin
        Application.MessageBox('文件名不能为空','警告',MB_OK);
        Exit;
      end;
      WBK := xlapp.workbooks.Open(Edit1.Text);
      sheet := xlapp.workbooks[1].worksheets['sheet1'];
      pc_i:=1;
      Edit2.Text := sheet.cells[pc_i,1];     //写入的话用 sheet.cells[pc_i,1] := Edit2.Tex;
      WBK.Close(SaveChanges := True);
      xlapp.Quit;
    end;