供你参考:
var info,filename:string;
myexcel:variant;
i,j:integer;
begin
if opendialog1.Execute then
begin
filename:=opendialog1.filename;
try
myexcel:=createoleobject('excel.application');
except
ShowMessage('无法打开Execl!');
Exit;
end;
myexcel.visible:=false;
myexcel.workbooks.open(filename);
myexcel.worksheets[1].activate;
info:='源数据库字段——→目标数据库字段'+#13;
for i:=1 to adoquery1.FieldCount do
info:=' '+info+trim(myexcel.cellS[1,i].value)+'——→'+adoquery1.Fields[i-1].fieldname+#13;
if messagedlg(info+#13+'请认真核对!是否继续?',mtConfirmation, [mbYes, mbNo], 0)=mryes then
begin
for i:=2 to myexcel.used.range.Rows.Count do begin
adoquery1.APPEND;
for j:=1 to adoquery1.FieldCount do begin
showmessage(inttostr(j)+':'+adoquery1.fields[j-1].asstring);
adoquery1.fields[j-1].asstring:=myexcel.cellS[i,j].value;
end;
adoquery1.post;
end;
end;
Myexcel.workbooks.close;
Myexcel.quit;
end;
end;
var info,filename:string;
myexcel:variant;
i,j:integer;
begin
if opendialog1.Execute then
begin
filename:=opendialog1.filename;
try
myexcel:=createoleobject('excel.application');
except
ShowMessage('无法打开Execl!');
Exit;
end;
myexcel.visible:=false;
myexcel.workbooks.open(filename);
myexcel.worksheets[1].activate;
info:='源数据库字段——→目标数据库字段'+#13;
for i:=1 to adoquery1.FieldCount do
info:=' '+info+trim(myexcel.cellS[1,i].value)+'——→'+adoquery1.Fields[i-1].fieldname+#13;
if messagedlg(info+#13+'请认真核对!是否继续?',mtConfirmation, [mbYes, mbNo], 0)=mryes then
begin
for i:=2 to myexcel.used.range.Rows.Count do begin
adoquery1.APPEND;
for j:=1 to adoquery1.FieldCount do begin
showmessage(inttostr(j)+':'+adoquery1.fields[j-1].asstring);
adoquery1.fields[j-1].asstring:=myexcel.cellS[i,j].value;
end;
adoquery1.post;
end;
end;
Myexcel.workbooks.close;
Myexcel.quit;
end;
end;
解决方案 »
- fastreport如何实现只打刚编辑保存的记录呢?
- function sum(expr:varint;band:variant=0;flags:Integer=0):variant 是什么意思 FASTREPORT 里的
- 扫描仪的应用问题。。
- VclZip的使用?请大家帮忙,谢谢!
- 从没见过这东西.
- DBGrid中大批的数据怎样导成XML文档?!!急!!先行谢过!
- 数据精度比较问题!
- 请问各位,如何用Printer实现选择页的打印,我只想打印第3页到第6页,如何实现???????????????????
- 用QuickReport画报表,斜线如何画啊,还有Delphi中没有专门画线的控件吗,小弟初涉Delphi
- delphi怎样读取系统的字体
- 请问 updatesql 能不能想query一样设置 params 参数,如果能,怎样设置
- 用TMediaPlayer如何播放.dat格式的视频文件?
OLEContainer1.createobjectfromfile(Filenamestring,false);