请高手赐教
本人第一次做导入
希望给我具体的代码和步骤!
先谢谢各位大虾了
本人第一次做导入
希望给我具体的代码和步骤!
先谢谢各位大虾了
解决方案 »
- 深圳的哥们都进来啊。。。。有点事情想问一下
- 简单问题,请大家帮忙!
- 一个“运行时的错误提示”问题——————在线等待!!!
- ★★★★★急!救命!两台Windows XP电脑如何互联?
- delphi中调用webservice时,出错,请大虾帮忙~~~
- 急!急!急!200分求现在可用的google 地址或 连接!!!
- 急啊,好简单的问题,有关窗口显示属性
- DBEdit的问题
- 关于ADOQuery 运行MSSQL的 delete 命令错误问题
- 有谁用过DEV express系列的dxdbgrid??它是如何把一个文本文件txt读到dxdbgrid1.columns[i]的picklist中去,作为picklist的内容的啊?
- 低价转让基本Delphi书籍!
- Memo控件,如何删除最后一行后光标不能在移到该行。。
1、通过Excel的VBA实现数据的导入。
2、通过Delphi的TExcelApplication、TExcelWorkBook和TExcelWorksheet等控件实现数据导入。
3、通过Dev Express的TcxSpreadSheetBook控件实现数据的导入。
var
ExcelApp,WorkBook,worksheet: OLEVariant;
col,row:integer;
i,j:integer;
begin
try
ExcelApp:=CreateOleObject('Excel.Application');
WorkBook:=CreateOleobject('Excel.Sheet');
except
application.Messagebox('无法打开Xls文件,请确认已经安装EXCEL.','', mb_OK+mb_IconStop);
Exit;
end;
ExcelApp.Visible := false;
if opgxls.Execute then
begin
try
adotable2.DisableControls;
workBook:= ExcelApp.workBooks.Open(OpgXls.FileName);
except
Application.MessageBox('你没有选中表','',mb_ok+mb_iconstop);
exit;
end; worksheet:=ExcelApp.workbooks[1].worksheets[1];
col:=worksheet.usedrange.columns.count;
row:=worksheet.usedrange.rows.count;
try
For i:=3 to row do
begin
adotable2.Append;
For j:=1 to col do
if j<=adotable2.FieldCount then
adotable2.Fields[j-1].Value:=worksheet.cells[i,j].value;
adotable2.post;
end;
finally
adotable2.EnableControls;
Application.ProcessMessages;
ExcelApp:=Unassigned;
workBook.close;
end;
end;end;
为什么会出现 could not convert variant of type(olestr) into type(boolean)
的错误啊
我是先把数据库导出到excel,再把sql中的数据删掉,再进行导入的
格式应该一致的啊
如何关闭excel啊
你这样做的话,进程里一直有excel的进程
var
ns:word;begin
ns:=wddonotsavechanges;
wdapp.quit(ns,emptyparam,emptyparam);//wdapp:wordapplication
mydoc:=nil;//mydoc:worddocument
end;
1.用ADO連接EXCEL,當數據源來進行數據庫的操作。
2.通過OLE的建立讀寫EXCEL文件。建議采用第二種方法,因為第一種方法在讀取EXCEL時,如果EXCEL表格的某一字段類型是數字時,將會讀取不到,
因為這時只能處理字符型的。
还可以通过 ADO,将EXCEL作为一个数据库,通过 遍历数据集,然后 循环插入var tmpsource,tmpdest:tadoquery;
i:integer;
reccount:string;
begin
dm_main.adocnmain.BeginTrans;
tmpsource:=tadoquery.Create(nil);
tmpsource.ConnectionString:='provider=microsoft.jet.oledb.4.0;data source='+edt_file.Text+
';extended properties =excel 8.0;persist security info=false';
tmpdest:=tadoquery.Create(nil);
tmpdest.ConnectionString:=adocnmain.ConnectionString; try
with tmpsource do
begin
sql.Clear;
sql.Add('select * from [sheet1$]');
open;
end;
gauge1.MaxValue :=tmpsource.RecordCount;
tmpsource.First;
reccount:=inttostr(tmpsource.RecordCount);
//ShowMessage(reccount);
try
for i:=0 to tmpsource.RecordCount-1 do
begin
with tmpdest do
begin
sql.Clear;
sql.Add('insert into table(f1,f2,f3)');
sql.Add('values (:v1,:v2,:v3)');
parameters.ParamByName('v1').Value :=tmpsource.FieldByName('f1').AsString;
parameters.ParamByName('v2').Value:=tmpsource.FieldByName('f2').AsString;
parameters.ParamByName('v3').Value:=tmpsource.FieldByName('f3').AsString;
execsql;
end;
tmpsource.Next;
gauge1.AddProgress(gauge1.MaxValue div tmpsource.RecordCount);
end;
adocnmain.CommitTrans;
application.MessageBox('数据导入成功!','提示',mb_ok+mb_iconinformation);
close;
except
on e:excpetion do
begin
adocnmain.RollbackTrans;
application.MessageBox('数据导入失败!请确定文件存在并且格式正确!','警告',mb_ok+mb_iconwarning);
end;
end;
finally
tmpsource.Free;
tmpdest.Free;
end;