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;
这个过程在程序中的实现,以下是代码: 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;
呵呵,试试这个 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;
错了,应该这样 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;
to xxmmmx(踢踏) AA.DoCmd.TransferSpreadsheet(acImport,acSpreadsheetTypeExcel8,sacTableName,sPathNameStr,true,'');
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;
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;
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;
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;
上面这句提示acimport,acSpreadsheetTypeExcel8没有定义
忘了告诉你了,要使用ComObj和Access2000单元,机子上要有Access2000.
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ADODB, ComObj, DB, Access2000, PubData, ComCtrls, StdCtrls, Buttons,
ExtCtrls;
AA.DoCmd.TransferSpreadsheet(acImport,acSpreadsheetTypeExcel8,sacTableName,sPathNameStr,true,'');
改为: AA.DoCmd.TransferSpreadsheet(acExport,acSpreadsheetTypeExcel8,sTableName,sPathNameStr,true,'');
acSpreadsheetTypeExcel5
acSpreadsheetTypeExcel7
acSpreadsheetTypeExcel8
acSpreadsheetTypeExcel9
是一下以前的版本7或5或4