读取excel循环语句
excel数据为:以下代码读取时,没有update到2017-09-10数据,后面还有2017-09-112017-09-12 等数据
var
iRE:Integer;
iRow,iCol :Integer;
MsExcel,MsExcelWorkBook,MsExcelWorkSheet:Variant;
i:Integer;
eicol:Integer;
eirow:Integer;
begin
Try
OpenDialog1.FileName:='*.xls';
if not OpenDialog1.Execute then
begin
Exit;
end;
if ExtractFileExt(OpenDialog1.FileName) <> '.xls' then
begin
MessageBox(0, '请选择正确的excel文件',PChar('提示'),MB_OK or MB_ICONWARNING);
Exit;
end;
MsExcel:=CreateOleObject('Excel.Application');
MsExcel.visible:=true;
MsExcelWorkBook:=MsExcel.WorkBooks.Open(OpenDialog1.FileName);
Application.ProcessMessages;//防止进程阻塞
iRow:=2;
iCol:=1;
i:=1;
while trim(msExcel.WorkSheets['sheet1'].Cells.value) <> '' do begin
with query.Close;
query.SQL.Text := 'update wh_dict set wh_amount=:wh_ amountwhere wh_id= :wh_idand wh_name:=wh_name andin_date:=in_date;
Parameters.ParamByName('wh_id').Value := Trim(msExcel.WorkSheets.Cells.value);
Parameters.ParamByName('wh_name').Value := Trim(msExcel.WorkSheets.Cells.value);
Parameters.ParamByName(' wh_amount').Value := Trim(msExcel.WorkSheets.Cells.value);
Parameters.ParamByName('duty_date').Value := Trim(msExcel.WorkSheets.Cells.value);
ExecSQL;
end;
iRow:=iRow+1;
end;
MsExcel.Quit;
Except
MessageBox(self.Handle,'数据导入失败!','系统提示',0);
MsExcel.Quit;
Exit;
end ;
MessageBox(self.Handle,'数据导入成功!','系统提示',0);
end;
帮你顶一下 不会delphi{:10_266:}
页:
[1]