Delphi将excel数据导入到数据库中源码

上传人:平*** 文档编号:13300591 上传时间:2017-10-23 格式:DOC 页数:10 大小:63.77KB
返回 下载 相关 举报
Delphi将excel数据导入到数据库中源码_第1页
第1页 / 共10页
Delphi将excel数据导入到数据库中源码_第2页
第2页 / 共10页
Delphi将excel数据导入到数据库中源码_第3页
第3页 / 共10页
Delphi将excel数据导入到数据库中源码_第4页
第4页 / 共10页
Delphi将excel数据导入到数据库中源码_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《Delphi将excel数据导入到数据库中源码》由会员分享,可在线阅读,更多相关《Delphi将excel数据导入到数据库中源码(10页珍藏版)》请在金锄头文库上搜索。

1、Delphi 将 excel 数据导入到数据库中源码procedure Tfrmexceltodata.Button4Click(Sender: TObject);constBeginRow= 1; BeginCol= 2; var iRE:Integer; iRow,iCol :Integer; /列、行 MsExcel,MsExcelWorkBook,MsExcelWorkSheet:Variant;adoquery1:TADOQuery;sqlstr1,sqlstr2:string;beginTryOpenDialog1.FileName:=*.xls;if not OpenDialog

2、1.Execute thenbeginExit;end;if ExtractFileExt(OpenDialog1.FileName) dobeginwith adoquery1 dobeginClose;SQL.Clear;SQL.Add(sqlstr1);SQL.Add(sqlstr2);Parameters.ParamByName(bh).Value :=StrToInt(djbh)+iCol-1;/Parameters.ParamByName(lwrq1).Value :=dtp1.DateTime;Parameters.ParamByName(lwrq).Value :=Trim(m

3、sExcel.WorkSheets1.CellsiCol,iRow.value);Parameters.ParamByName(lwdw).Value :=Trim(msExcel.WorkSheets1.CellsiCol,iRow+2.value);Parameters.ParamByName(lwybh).Value :=Trim(msExcel.WorkSheets1.CellsiCol,iRow+3.value);Parameters.ParamByName(wjzbh).Value :=Trim(msExcel.WorkSheets1.CellsiCol,iRow+1.value)

4、;/Parameters.ParamByName(wjzbh).Value :=lwbh+inttostr(icol-1);/Trim(msExcel.WorkSheets1.CellsiCol,iRow+1.value); Parameters.ParamByName(nrzy).Value :=Trim(msExcel.WorkSheets1.CellsiCol,iRow+4.value);Parameters.ParamByName(ys).Value :=1;Parameters.ParamByName(lwfs).Value :=1;Parameters.ParamByName(wj

5、dl).Value :=cbb6.text;Parameters.ParamByName(wjxl).Value :=cbb7.text;/ Parameters.ParamByName(wjnd).Value :=FormatDateTime(yyyy,now();Parameters.ParamByName(wjnd).Value :=cbb1.Text;Parameters.ParamByName(sywb).Value :=0;Parameters.ParamByName(pswb).Value :=0;Parameters.ParamByName(wjzt).Value :=未送阅签

6、;Parameters.ParamByName(sfqt).Value :=0;ExecSQL;end;iCol:=iCol+1;end;MsExcel.Quit;ExceptMessageBox(self.Handle,数据导入失败!,系统提示,0);MsExcel.Quit;Exit;end;/end tryMessageBox(self.Handle,数据导入成功!,系统提示,0);frmexceltodata.Close; end;请问,用 Delphi 如何写程序将 Excel 或 txt 导入 oracle?请问各位,用 Delphi 如何写程序将 Excel 或 txt 导入 o

7、racle,不用导入工具,写代码,谢谢!procedure TForm1.button1Click(Sender: TObject);vari,row,column:integer;beginTryExcelApplication1.Connect;ExceptMessageDlg(Excel may not be installed,mtError, mbOk, 0);Abort;End;ExcelApplication1.Visible0:=True;ExcelApplication1.Caption:=Excel Application;ExcelApplication1.Workboo

8、ks.Add(Null,0);ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks1);ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets1 as _Worksheet);Table1.Open;row:=1;While Not(Table1.Eof) dobegincolumn:=1;for i:=1 to Table1.FieldCount dobeginExcelWorksheet1.Cells.Itemrow,column:=Table1.fieldsi-1.AsString;col

9、umn:=column+1;end;Table1.Next;row:=row+1;end;end;我用这代码,导不进数据库。还有怎样导入指定路径的文件?谢谢昵称: panda831102 时间: 2010-09-07 09:50:14excel 導入 sql 的,導 oracle 的自己轉換修改一下代碼試試:Delphi(Pascal) codeprocedure TRES_DCC_ECRN_F.cxButton1Click(Sender: TObject);varExcelApp,WorkBook:Olevariant;ExcelSheetCount,i,k:Integer;begininh

10、erited;if RzButtonEdit1.Text .xls) thenbeginMessageDlg(請選擇要導入的 Excel 檔案!,mtWarning,mbOK,0);RzButtonEdit1.Clear; endelsebegintryApplication.ProcessMessages;ExcelApp:=CreateOleObject(Excel.Application);WorkBook:=ExcelApp.WorkBooks.Open(RzButtonEdit1.Text);ExcelApp.Visible:=False;ExcelSheetCount:=WorkB

11、ook.WorkSheets.Count;for i:=1 to ExcelSheetCount dobeginScreen.Cursor:=crSQLWait;WorkBook.WorkSheetsi.Activate;a:=ExcelApp.Cells4,2.Value;b:=ExcelApp.Cells8,2.Value;c:=ExcelApp.Cells14,2.Value;d:=ExcelApp.Cells21,2.Value;e:=ExcelApp.Cells22,2.Value;f:=ExcelApp.Cells23,2.Value;if (Copy(Trim(a),1,3) a

12、nd (Copy(Trim(a),1,3) thenbeginMessageDlg(檔案格式錯誤!,mtWarning,mbOK,0);InsertErrorLOG;Screen.Cursor:=crDefault;Exit;end;with adoq_ecrn dobeginClose;SQL.Text:=select * from RES_ECR_TYPE where ECRNO=+ a+;Open;if RecordCount=1 thenbeginMessageDlg(請檢查:導入檔案時編號+ a+的記錄重復!,mtWarning,mbOK,0);InsertRepeatLOG;Scr

13、een.Cursor:=crDefault;Exit;end;end;with adoq_ecrn dobeginClose;SQL.Clear; SQL.Add(insert into RES_ECR_TYPE(ECRNO,DESOFCHANGE,RELEASEDATE,RESPEOPLE,ISSUEDEPT,MODEL) values(:a,:b,:c,:d,:e,:f);Parameters.ParamByName(a).Value:=a;Parameters.ParamByName(b).Value:=b;Parameters.ParamByName(c).Value:=Trim(Co

14、py(c,1,19);Parameters.ParamByName(d).Value:=d;Parameters.ParamByName(e).Value:=e;Parameters.ParamByName(f).Value:=f;ExecSQL;end;InsertECRLOG;ProgressBar1.Min:=0;ProgressBar1.Max:=ExcelSheetCount;for k:=33 to WorkBook.WorkSheetsi.usedrange.rows.count dobeging:=ExcelApp.CellsK,1.Value;q:=ExcelApp.Cell

15、sk,2.Value;w:=ExcelApp.Cellsk,3.Value;v:=ExcelApp.Cellsk,4.Value;r:=ExcelApp.Cellsk,5.Value;t:=ExcelApp.Cellsk,6.Value;y:=ExcelApp.Cellsk,7.Value;u:=ExcelApp.Cellsk,8.Value;o:=ExcelApp.Cellsk,9.Value;if (q) thenwith adoq_item dobeginClose;SQL.Clear;SQL.Add(insert into RES_ECR_ITEM(GROUPID,ECRNO,ITEMNO,ITEMDESPTION,FZRELATION,CHANGETYPE,BEFORECHANGE,AFTERCHANGE,PROPOSE,REMARK) values(:g,:p,:q,:w,:v,:r,:t,:y,:u,:o);Parameters.ParamByName(g).Value:=g;Parameters.ParamByName(p).Value:=a;Parameters.ParamByName(q).Value:=q;Parameters.ParamByName(w).V

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号