procedure TForm1.Button1Click(Sender: TObject);
var i,k:integer;
ExcelID: Variant;
code,ifsix:string;
begin
if opendialog1.Execute then begin
ExcelID:=CreateOleObject('Excel.Application');
ExcelID.workbooks.open(opendialog1.FileName);
ExcelID.WorkSheets[1].Activate;
i:=ExcelID.worksheets[1].UsedRange.Rows.Count;
for k:=1 to i-1 do begin
code:= copy(ExcelID.Cells[k+1,1].Value,1,6);
ifsix:=copy(ExcelID.Cells[k+1,1].Value,1,1);
with adoquery2 do
begin
close;
sql.Clear;
sql.Add('select * from diannei where ProductBarcode='+code+'') ;
open;
end;
if (adoquery2.RecordCount <= 0) and (ifsix <>'6') then
begin
adoquery1.Append;
adoquery1.Fields[0].AsString:= code;
adoquery1.Fields[1].AsString:=ExcelID.Cells[k+1,2].Value;
adoquery1.Fields[2].AsString:='3';
adoquery1.Post;
end;
end;
adoquery1.Close;
ExcelID.quit;
showmessage('ok');
end;
end;