各位大俠!!幫幫忙!!!關於數據導入的問題!!!!急急急!!!!!!!!!!!!!!!!!!!!!! ( 积分: 20 )

W

wtx047

Unregistered / Unconfirmed
GUEST, unregistred user!
我想將任意一張excel表格導入到access中的一張空表(t)中,以下代碼是我看了大俠門的相關帖子後搞下來的,
procedure TForm1.Button1Click(Sender: TObject);
var xlsName : String;
begin
OpenDialog1.Filter := '*.XLS|*.XLS';
OpenDialog1.DefaultExt := 'XLS';
if OpenDialog1.Execute then
begin
xlsName := OpenDialog1.FileName;
ADOConnection1.Connected := false;
ADOQuery1.Connection := ADOConnection1;
adoconnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:/db1.mdb;Persist Security Info=False ';
ADOConnection1.Connected := true;
ADOConnection1.Execute('select * into [t] from [excel8.0;database=xlsName.XLS].[t$]');
adoconnection1.Connected:=true;
end;
end;
但是運行報錯,錯誤提示是:"t$"找不到,我改偽“sheet1$”還是報錯偽:“sheet1$”找不到。郁悶!!!!!
哪位大俠幫幫忙,解決以下轉這個遺體,我也看了論壇上的相關帖子,還是沒找到答案,如果這程序不可以,就請大俠門給個代碼!謝謝了!!!我的想法是:通過opendialog來選擇一個excel文檔然後導入到access中的一張空表(t)中,不是固定路徑的excel導入到access中。謝謝!!!!!!!
 
我想將任意一張excel表格導入到access中的一張空表(t)中,以下代碼是我看了大俠門的相關帖子後搞下來的,
procedure TForm1.Button1Click(Sender: TObject);
var xlsName : String;
begin
OpenDialog1.Filter := '*.XLS|*.XLS';
OpenDialog1.DefaultExt := 'XLS';
if OpenDialog1.Execute then
begin
xlsName := OpenDialog1.FileName;
ADOConnection1.Connected := false;
ADOQuery1.Connection := ADOConnection1;
adoconnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:/db1.mdb;Persist Security Info=False ';
ADOConnection1.Connected := true;
ADOConnection1.Execute('select * into [t] from [excel8.0;database=xlsName.XLS].[t$]');
adoconnection1.Connected:=true;
end;
end;
但是運行報錯,錯誤提示是:"t$"找不到,我改偽“sheet1$”還是報錯偽:“sheet1$”找不到。郁悶!!!!!
哪位大俠幫幫忙,解決以下轉這個遺體,我也看了論壇上的相關帖子,還是沒找到答案,如果這程序不可以,就請大俠門給個代碼!謝謝了!!!我的想法是:通過opendialog來選擇一個excel文檔然後導入到access中的一張空表(t)中,不是固定路徑的excel導入到access中。謝謝!!!!!!!
 
uses ComObj;
我是试着用一个表格控件,先读出Excel里的数据,然后再写进表里。
if SourDir.Execute then
begin
if not msgshow(handle,'确认要提取数据吗?',false) then exit;
Prow:=0;
ExcelApp := CreateOleObject( 'Excel.Application' );
ExcelApp.WorkBooks.Open(SourDir.FileName);
with spg_show do
begin
cells[1,Prow]:=copy(ExcelApp.Cells[ARow,Asfz],i-AJqcd+1,AJqcd);
cells[2,Prow]:=ExcelApp.Cells[ARow,Abm];
cells[3,Prow]:=ExcelApp.Cells[ARow,Axm];
cells[4,Prow]:=P_ReadIni('jkjcb','cjyy','');
cells[5,Prow]:=ExcelApp.Cells[ARow,Adh];
cells[6,Prow]:=FormatDateTime('yyyy-mm-dd',date);
cells[7,Prow]:=ExcelApp.Cells[ARow,Axb];
cells[8,Prow]:=ExcelApp.Cells[ARow,Anl];
cells[9,Prow]:=ExcelApp.Cells[ARow,Ajg];
cells[10,Prow]:=ExcelApp.Cells[ARow,Ahy];
cells[11,Prow]:=ExcelApp.Cells[ARow,Asfz];
cells[12,Prow]:=ExcelApp.Cells[ARow,Azc];
end;
end;
end;
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
end;
 
http://www.delphibbs.com/keylife/iblog_show.asp?xid=13398
 
多人接受答案了。
 
顶部