Excel 导入库的问题(10分)

  • 主题发起人 主题发起人 gymmy
  • 开始时间 开始时间
来自:yzhshi, 时间:2002-7-5 18:10:00, ID:1189561
可以呀。Ado
设置属性ConnetionString
选择 Microsoft Jet 4.0 OLE DB provider
Select or enter a datasorce name -> 选择你要打开Excel文件
User name默认是Admin 密码默认为空,可以不用理会
Extended properties 设为:Excel 8.0
sql语句 select * from [yourtablename]
(注意要有[])
以后的工作就是看你的了。
以后的工作:
select * into [aaa.mdb].aaa from [sheet1];
:)
 
还不如一开始就写代码呢!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, Grids, DBGrids, ADODB;

type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
ADOTable2: TADOTable;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
DataSource2: TDataSource;
DBGrid2: TDBGrid;
Button1: TButton;
ADOTable1djid: TWideStringField;
ADOTable1bbid: TWideStringField;
ADOTable1nameid: TWideStringField;
ADOTable1dj: TBCDField;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
i,j:Integer ;
begin
showmessage(inttostr(ADOTable1.RecordCount)) ;
for j:=0 to ADOTable1.RecordCount -1 do

begin
ADOTable2.Append ;

for i:=0 to ADOTable1.Fields.Count -1 do

begin
ADOTable2.Fields.Value :=ADOTable1.Fields.Value ;
end;
ADOTable2.Post ;

ADOTable1.Next ;
end;
end;

end
 
ADOTable1.ConnectionString 如下
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=
D:/Documents and Settings/administrator/桌面/Book1.xls
;Extended Properties=Excel 8.0;Persist Security Info=False
adotable2连sqlserver就可以了
 
谢谢xiaofeng,我已经用ole直接从excel中导入了,不过你的方法更简单。你真是个好人,你是从是软件工作的吗?
 
连接好excel表后
sql语句 select * from [sheet$1]
这样对吗??
 
我试过了,是这样的!
 
后退
顶部