请问,如何设计delphi程序界面,选中一个EXCEL文件,将EXCEL中的数据导入到ACCESS或SQL SERVER 2000数据库中.
解决方案 »
- dbexpress
- 关于ADO记录指针?
- 在WIN2000下自定义打印机纸张大小
- adoConnection 与 sqlserver 的连接
- 关于table的查找问题
- 谁有关于怎样使用installshield(express-borland limited edition)的书籍或文章吗?谢谢!
- 有关StringGrid的问题!
- 如何可知道当前控件在屏幕中的位置(Left,Top),而不是在其Parent中的位置?
- 大虾帮我推荐一个好用的grid控件
- DELPHI 连接ACCESS 2000 奇怪现象!一定送高分
- 有何方法将一个自定义的函数转成一个控件,并将其返回值赋给ASP网页中的一个文本框
- 替换代码的问题
var
a_cc: TStrings;
ExcelApp: Variant;
begin
if OpenDialog1.Execute then begin
{打开保存一次EXCEL文件,为何要保存一次呢?如果是其它程序用第三方控件导出的EXCEL文件,最好做此步,否则容发生错误}
ExcelApp := CreateOleObject( 'Excel.Application' );
ExcelApp.WorkBooks.Open(OpenDialog1.FileName);
ExcelApp.ActiveWorkBook.Save;
ExcelApp.Quit;
varclear(ExcelApp);
a_cc :=TStringList.Create;
{ADOConn是数据库连接控件ADOConnection}
ADOConn.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + OpenDialog1.FileName + ';Extended Properties=excel 8.0;Persist Security Info=false';
ADOConn.Connected := True;
ADOConn.GetTableNames(a_cc);{将EXCEL文件中的表格名单赋值于a_cc变量}
with adoquery2 begin
Close;
sql.text:='select * from ['+a_cc[0]+']';//得到EXCEL文件中的第一个表格的数据
open;
while not eof begin
adoquery1.Append;
adoquery1.FieldByName('xf_a').AsString:=FieldValues['工号'];
adoquery1.FieldByName('xf_b').AsString:=FieldValues['姓名'];
adoquery1.FieldByName('xf_c').AsString:=FieldValues['部门'];
adoquery1.post;
next;
end;
close;
end;
adoconn.Connected:=false;
a_cc.Free;
messagebox(handle,'数据处理完毕','提示',MB_OK+MB_ICONINFORMATION);
end;
end;
var
str:string;
begin
str:='select * into 表 from opendatasource(''microsoft.jet.oledb.4.0'',''data source=''文件名'';user id=admin;password=;extended properties=excel 5.0'')...[sheet1$]';
with adoquery1 do
begin
close;
sql.clear;
sql.add(str);
open;
end;
end;
var
ExcelApp: Variant;
strv,str:string;
begin
if OpenDialog1.Execute then begin
{打开保存一次EXCEL文件,为何要保存一次呢?如果是其它程序用第三方控件导出的EXCEL文件,最好做此步,否则容发生错误}
ExcelApp := CreateOleObject( 'Excel.Application' );
ExcelApp.WorkBooks.Open(OpenDialog1.FileName);
strv:=ExcelApp.WorkSheets[1].name;
ExcelApp.ActiveWorkBook.Save;
ExcelApp.Quit;
varclear(ExcelApp);
str:='select * into 表 from opendatasource(''microsoft.jet.oledb.4.0'',''data source=''文件名'';user id=admin;password=;extended properties=excel 5.0'')...['+strv+'$]';
with adoquery1 do
begin
close;
sql.clear;
sql.add(str);
open;
end;
end;
end;
也能给我一个份子例子吗?
Excel to MSSQL
[email protected]
导入导出都很简单。
多谢大侠。能否把你的例子发给我一份呢
Email:[email protected]