资源描述:
《将excel表格导入dbf数据库的实例》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、下面一段代码是将EXCEL表格导入DBF数据库的实例usescomobj;procedureTexcelfrm.Button1Click(Sender:TObject);varoe:variant;n1:string;i,j:integer;begin oe:=CreateOleObject('Excel.Application'); oe.visible:=true; oe.workbooks.open(FileListBox1.FileName); j:=2; //假定标题在第一行 trywit
2、hadoQuery1do begin n1:='insertintotablename(fieldslist)values(:fieldslist)'; close; sql.Clear; sql.Add(n); whileoe.worksheets[sheetname].cells[j,1].text<>''do begin fori:=1to列数do Parameters.Items[i-1].Value:=oe.worksheets[sheet
3、name].cells[j,i].text; execsql; j:=j+1; end;oe.visible:=false; showmessage('导入完毕'); end; except oe.visible:=false; showmessage('数据库错误或有重复编号,请检查'); end;end; 回复人:gg1335 回复时间:2004-8-209:05:00下面的代码是导出为EXCELunitUnit1;interfaceuses W
4、indows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs, Grids,DBGrids,Db,DBTables,StdCtrls,Excel97,OleServer,ComObj,ActiveX;type TForm1=class(TForm) Button1:TButton; Table1:TTable; DataSource1:TDataSource; DBGrid1:TDBGrid; ExcelAppl
5、ication1:TExcelApplication; ExcelWorkbook1:TExcelWorkbook; ExcelWorksheet1:TExcelWorksheet; SaveDialog1:TSaveDialog; procedureButton1Click(Sender:TObject); procedureFormCreate(Sender:TObject); procedureFormDestroy(Sender:TObject); private
6、 {Privatedeclarations} public {Publicdeclarations} ExcelFormatNum:TStrings;//ExcelFormatNum ExcelFormatStr:TStrings;//ExcelFormatStr functionExportDBGrid(DBGrid:TDBGrid;SheetName:string):boolean;//直接保存,不显示EXCEL functionExportDataToExcelV(S
7、heetName:string;DBGrid:TDBGrid;ExcelApplication:TExcelApplication; ExcelWorkbook:TExcelWorkbook;ExcelWorksheet:TExcelWorksheet):boolean;//显示EXCEL functionConvertIntToCharacters(IntNumber:Integer):string; functionGetNumberFormat(s:string):string;/
8、/判断字段的格式 functionFindExcelFormatStr(s:string):Boolean;//找字符格式 functionFindExcelFormatNum(s:string):Boolean;//找数字格式 end;var Form1:TForm1;implementation{$R*.DFM}functionTForm1.Expor