导入EXCEL到数据库中
var
sFileName, sTableName: string;
sl: TStringList;
i: integer;
conn: TADOConnection;
dialog: TOpenDialog;
begin
dialog := TOpenDialog.Create(Application);
if not dialog.Execute then Exit;
try
sFileName := dialog.FileName;
conn := TADOConnection.Create(Application);
conn.Connected := False;
conn.ConnectionString := ‘Provider=Microsoft.Jet.OLEDB.4.0;Password="";Data Source=‘ +
sFileName + ‘;Extended Properties="Excel 8.0;IMEX=1";Persist Security Info=False‘;
conn.Connected := True;
sl := TStringList.Create;
conn.GetTableNames(sl); // 记住 Excel 文件的 底部 必须是 sheet1 否则不能导入
sTableName := sl[0];
if Pos(‘$‘, sTableName) > 0 then sTableName := ‘[‘ + sTableName + ‘]‘;
with sourceds do
begin
connection := conn;
Close;
SQL.Clear;
SQL.Text := ‘SELECT * FROM ‘ + sTableName;
Open;
end;
sl.Free;
if sourceds.isempty then Exit;
with destds do
begin
Close;
sql.clear;
Sql.Text := ‘SELECT top 1 * FROM sp where 1=0‘;
Open;
end;
sourceds.First;
while not sourceds.eof do
begin
destds.Append;
destds.FieldValues[‘编号‘] := sourceds.FieldValues[‘编号‘];
destds.FieldValues[‘名称‘] := sourceds.FieldValues[‘名称‘];
destds.FieldValues[‘价格‘] := sourceds.FieldValues[‘价格‘];
destds.Post;
sourceds.Next;
end;
Conn.Free;
dialog.Free;
showmessage(‘Import success‘)
except
showmessage(‘Import fail‘)
end;
http://c.tieba.baidu.com/p/3329567026
http://c.tieba.baidu.com/p/3329564871
http://c.tieba.baidu.com/p/3329560410
http://c.tieba.baidu.com/p/3329556518
http://c.tieba.baidu.com/p/3329554902
http://c.tieba.baidu.com/p/3329553076
http://c.tieba.baidu.com/p/3329554902
http://c.tieba.baidu.com/p/3329553076
http://c.tieba.baidu.com/p/3329553076
http://c.tieba.baidu.com/p/3329551672
http://c.tieba.baidu.com/p/3329550368
http://c.tieba.baidu.com/p/3329548487
http://c.tieba.baidu.com/p/3329545174
http://c.tieba.baidu.com/p/3329543367
http://c.tieba.baidu.com/p/3329541357
http://c.tieba.baidu.com/p/3329513768
http://c.tieba.baidu.com/p/3329510087
http://c.tieba.baidu.com/p/3329508053
http://c.tieba.baidu.com/p/3329504697
http://c.tieba.baidu.com/p/3329502849
http://c.tieba.baidu.com/p/3329500242
http://c.tieba.baidu.com/p/3329496545
http://c.tieba.baidu.com/p/3329494880
http://c.tieba.baidu.com/p/3329494561
http://c.tieba.baidu.com/p/3329493132
http://c.tieba.baidu.com/p/3329487412
http://c.tieba.baidu.com/p/3329470145
http://c.tieba.baidu.com/p/3329459436
http://c.tieba.baidu.com/p/3329457216
http://c.tieba.baidu.com/p/3329455750
http://c.tieba.baidu.com/p/3329454020
http://c.tieba.baidu.com/p/3329451732
http://c.tieba.baidu.com/p/3329450267
http://c.tieba.baidu.com/p/3329447730
http://c.tieba.baidu.com/p/3329446222
http://c.tieba.baidu.com/p/3329444229
http://c.tieba.baidu.com/p/3329435945
http://c.tieba.baidu.com/p/3329414428
http://c.tieba.baidu.com/p/3329414149
http://c.tieba.baidu.com/p/3329394816
http://c.tieba.baidu.com/p/3329387713
http://c.tieba.baidu.com/p/3329386455
http://c.tieba.baidu.com/p/3329374372
http://c.tieba.baidu.com/p/3329367023
http://c.tieba.baidu.com/p/3329365913
http://c.tieba.baidu.com/p/3329364730
http://c.tieba.baidu.com/p/3329362327
http://c.tieba.baidu.com/p/3329360535
http://c.tieba.baidu.com/p/3329359297
http://c.tieba.baidu.com/p/3329334009
http://c.tieba.baidu.com/p/3329331982
http://c.tieba.baidu.com/p/3329320784
http://c.tieba.baidu.com/p/3329317357
http://c.tieba.baidu.com/p/3329302280
http://c.tieba.baidu.com/p/3329300080
http://c.tieba.baidu.com/p/3329295767
http://c.tieba.baidu.com/p/3329292909
http://c.tieba.baidu.com/p/3329290788
http://c.tieba.baidu.com/p/3329289532
http://c.tieba.baidu.com/p/3329287780
http://c.tieba.baidu.com/p/3329285593
http://c.tieba.baidu.com/p/3329284330
http://c.tieba.baidu.com/p/3329282063
http://c.tieba.baidu.com/p/3329280731
http://c.tieba.baidu.com/p/3329279054
http://c.tieba.baidu.com/p/3329277183
http://c.tieba.baidu.com/p/3329275726
http://c.tieba.baidu.com/p/3329272696
http://c.tieba.baidu.com/p/3329277183
http://c.tieba.baidu.com/p/3329275726
http://c.tieba.baidu.com/p/3329270986
http://c.tieba.baidu.com/p/3329267655
http://c.tieba.baidu.com/p/3329266454
http://c.tieba.baidu.com/p/3329263856
http://c.tieba.baidu.com/p/3329262594
http://c.tieba.baidu.com/p/3329261506
http://c.tieba.baidu.com/p/3329260339
http://c.tieba.baidu.com/p/3329257998
http://c.tieba.baidu.com/p/3329256195
http://c.tieba.baidu.com/p/3329254941
http://c.tieba.baidu.com/p/3329253559
http://c.tieba.baidu.com/p/3329252227
http://c.tieba.baidu.com/p/3329250834
http://c.tieba.baidu.com/p/3329247554
http://c.tieba.baidu.com/p/3329243235
http://c.tieba.baidu.com/p/3329242044
http://c.tieba.baidu.com/p/3329240525
http://c.tieba.baidu.com/p/3329239029
http://c.tieba.baidu.com/p/3329237838
http://c.tieba.baidu.com/p/3329236556
http://c.tieba.baidu.com/p/3329235184
http://c.tieba.baidu.com/p/3329233196
http://c.tieba.baidu.com/p/3329230442
http://c.tieba.baidu.com/p/3329224654
http://c.tieba.baidu.com/p/3329220135
http://c.tieba.baidu.com/p/3329206325
http://c.tieba.baidu.com/p/3329204137
http://c.tieba.baidu.com/p/3329202843
http://c.tieba.baidu.com/p/3329201487
http://c.tieba.baidu.com/p/3329202843
http://c.tieba.baidu.com/p/3329201487
http://c.tieba.baidu.com/p/3329200167
http://c.tieba.baidu.com/p/3329198365
http://c.tieba.baidu.com/p/3328881631
http://c.tieba.baidu.com/p/3328880285
http://c.tieba.baidu.com/p/3328878176
http://c.tieba.baidu.com/p/3328877152
http://c.tieba.baidu.com/p/3328876318
http://c.tieba.baidu.com/p/3328874948
http://c.tieba.baidu.com/p/3328872903
http://c.tieba.baidu.com/p/3328857660
http://c.tieba.baidu.com/p/3328715889
http://c.tieba.baidu.com/p/3328719176
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。