直接在Access中“文件|获取外部数据|导入”,选择Excel文件

解决方案 »

  1.   

    procedure TFShowProc.ImportExcel(sPathNameStr: String);
    var
      AA: OleVariant;
      sTempPath,sacTableName: String;
    begin
      sTempPath:='c:\windows\temp\temp.mdb';
      sacTableName:='Temp'
      try
        //创建Access Application对象,并打开Access临时数据库
        AA:=CreateOleObject('Access.Application');
        //如果不存在这个文件,则创建,否则,打开这个文件
        if not FileExists(sTempPath)
          then AA.NewCurrentDatabase(sTempPath)
          else AA.OpenCurrentDatabase(sTempPath,false);
        //转化成Excel2000的格式,具体可查看Access帮助    AA.DoCmd.TransferSpreadsheet(acImport,acSpreadsheetTypeExcel8,sacTableName,sPathNameStr,true,'');
        AA.CloseCurrentDatabase;
      except
        ShowMessage('文件格式有误,转换过程中发生错误!');
      end;
    end;
      

  2.   

    这个过程在程序中的实现,以下是代码:
    procedure TFShowProc.ImportExcel(sPathNameStr: String);
    var
      AA: OleVariant;
      sTempPath,sacTableName: String;
    begin
      sTempPath:='c:\windows\temp\temp.mdb';
      sacTableName:='Temp'
      try
        //创建Access Application对象,并打开Access临时数据库
        AA:=CreateOleObject('Access.Application');
        //如果不存在这个文件,则创建,否则,打开这个文件
        if not FileExists(sTempPath)
          then AA.NewCurrentDatabase(sTempPath)
          else AA.OpenCurrentDatabase(sTempPath,false);
        //转化成Excel2000的格式,具体可查看Access帮助
        AA.DoCmd.TransferSpreadsheet(acImport,acSpreadsheetTypeExcel8,sacTableName,sPathNameStr,true,'');
        AA.CloseCurrentDatabase;
      except
        ShowMessage('文件格式有误,转换过程中发生错误!');
      end;
    end;
      

  3.   

    呵呵,试试这个
    use ....,adodb;
    ....with TAdoConnection.Create(self) do try
      LoginPrompt:=false;
      ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\xsgl.mdb;Jet OLEDB:Database Password=111111;' ;
      open;
      execute('select * into [Excel 8.0;database=d:\aa].ddd from 销售信息');
    finally
      free;
    end;
      

  4.   

    错了,应该这样
    use ....,adodb;....
    with TAdoConnection.Create(self) do try
      LoginPrompt:=false;
      ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\xsgl.mdb;Jet OLEDB:Database Password=111111;' ;
      open;
      execute('select * into sss from [Excel 8.0;database=d:\aa].ddd');
    finally
      free;
    end;
      

  5.   

    to xxmmmx(踢踏) AA.DoCmd.TransferSpreadsheet(acImport,acSpreadsheetTypeExcel8,sacTableName,sPathNameStr,true,'');
        
    上面这句提示acimport,acSpreadsheetTypeExcel8没有定义
      

  6.   

    我是说用delphi写一个小程序写,答出来多加分 
      

  7.   


    忘了告诉你了,要使用ComObj和Access2000单元,机子上要有Access2000.
    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ADODB, ComObj, DB, Access2000, PubData, ComCtrls, StdCtrls, Buttons,
      ExtCtrls;
      

  8.   

    同时再问一下,反向转化如何做,access可能会有标题可以再加100分
      

  9.   

    这样吧,你在Servers页面拉进去一个'AccessApplication'控件,然后运行试试。
      

  10.   

    这一句
    AA.DoCmd.TransferSpreadsheet(acImport,acSpreadsheetTypeExcel8,sacTableName,sPathNameStr,true,'');
    改为:    AA.DoCmd.TransferSpreadsheet(acExport,acSpreadsheetTypeExcel8,sTableName,sPathNameStr,true,'');
      

  11.   

    它好像只支持access97还有它说acSpreadsheetTypeExcel8没有定义
      

  12.   

    acSpreadsheetTypeExcel4
    acSpreadsheetTypeExcel5
    acSpreadsheetTypeExcel7
    acSpreadsheetTypeExcel8
    acSpreadsheetTypeExcel9
    是一下以前的版本7或5或4