V
victor9871
Unregistered / Unconfirmed
GUEST, unregistred user!
现在程序导入excel没问题 数据库里面有个电话 ,导入次数字段,如果导入电话已经存在,就覆盖原来的电话,导入次数增加1,如果又导入的这个电话了,那导入次数增加1,导入次数为2了,如果是新的电话导入,默认的次数就为0。导入代码如下:procedure TFrm_Import.Btn_StartClick(Sender: TObject);var i,j,k,l,m,o,p,custcode:integer; F_Field:array [0..50] of String; //源字段 S_Field:array [0..50] of String; //映谢字段begin with Qry_Info do begin Edit; Post; end; with Qry_Field do begin Close; SQL.Clear; SQL.Add('select * from T_Import where F_Field<>'''+' '+''' and tablename='''+tablename+''''); Open; end; for i:=1 to Qry_Field.RecordCount do begin F_Field:=Qry_Field.FieldByName('F_Field').AsString; //源字段 S_Field:=Qry_Field.FieldByName('S_Field').AsString; //映谢字段 Qry_Field.Next; end; if tablename='custom' then begin Btn_Start.Enabled:=False; Screen.Cursor:=crHourglass; Frm_Data.OpenDataSet(Qry_Import,'Select * from custom'); o:=0; p:=0; for i:=1 to Frm_Main.b_row-1 do begin ProgressBar1.Max:=Frm_Main.b_row-1; Frm_Data.ADOConnection1.BeginTrans; try with Qry_Import do begin Append; For k:=1 to Qry_Field.RecordCount do begin m:=Frm_Main.ImportFields.IndexOf(F_Field[k])+1; for l:=1 to Qry_Field.RecordCount do begin FieldByname(S_Field[k]).AsString:=Frm_Main.eclApp.activesheet.cells.item[i+1,m].Text; end; end; Post; end; inc(o); Frm_Data.ADOConnection1.CommitTrans; except Frm_Data.ADOConnection1.RollbackTrans; Inc(p); end; ProgressBar1.Position:=i; end; MessageDlg(Pchar('导入数据完成,导入成功 '+inttostr(o)+' 条, 电话重复 '+inttostr(p)+' 条'),mtConfirmation, [mbOK], 0); Screen.Cursor:=crDefault; //-------------------------------------------------------------------------- end;end;