请问,如下代码为什么最后一个导不成功?
总是把最后一条删除
try
Excel := CreateOLEObject('Excel.Application');
except
Application.MessageBox('Excel没有安装!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Exit;
end;
Excel.Visible := false;
Excel.WorkBooks.Open(xlsFilename);
try
iRow := BeginRow;
iCol := BeginCol;
while trim(Excel.WorkSheets[1].Cells[iRow,1].value) <> '' do begin
with ADOQuery1 do begin
Append;
Fields[0].AsString := trim(Excel.WorkSheets[1].Cells[iRow,iCol].value);
Fields[1].AsString := trim(Excel.WorkSheets[1].Cells[iRow,iCol+1].value);
Fields[2].Asstring := trim(Excel.WorkSheets[1].Cells[iRow,iCol+2].value);
Fields[3].Asstring := trim(Excel.WorkSheets[1].Cells[iRow,iCol+3].value);
Fields[4].AsString := trim(Excel.WorkSheets[1].Cells[iRow,iCol+4].value);
Fields[5].Asstring := trim(Excel.WorkSheets[1].Cells[iRow,iCol+5].value);
Fields[6].Asstring := trim(Excel.WorkSheets[1].Cells[iRow,iCol+6].value);
Fields[7].AsString := trim(Excel.WorkSheets[1].Cells[iRow,iCol+7].value);
Fields[8].Asstring := trim(Excel.WorkSheets[1].Cells[iRow,iCol+8].value);
Fields[9].Asstring := trim(Excel.WorkSheets[1].Cells[iRow,iCol+9].value);
Fields[10].AsString := trim(Excel.WorkSheets[1].Cells[iRow,iCol+10].value);
Fields[11].AsString := trim(Excel.WorkSheets[1].Cells[iRow,iCol+11].value);
iRow := iRow + 1;
statusbar1.Panels[0].Text:='导入记录:'+inttostr(iRow-1)+'条';
end;
end;
Excel.Quit;
ADOQuery1.UpdateStatus ;
except
Application.MessageBox('导入数据出错!请检查文件的格式是否正确!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Excel.Quit;
end;
MessageBox(GetActiveWindow(), '数据导入成功!', '提示', MB_OK +
MB_ICONWARNING);
end;
总是把最后一条删除
try
Excel := CreateOLEObject('Excel.Application');
except
Application.MessageBox('Excel没有安装!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Exit;
end;
Excel.Visible := false;
Excel.WorkBooks.Open(xlsFilename);
try
iRow := BeginRow;
iCol := BeginCol;
while trim(Excel.WorkSheets[1].Cells[iRow,1].value) <> '' do begin
with ADOQuery1 do begin
Append;
Fields[0].AsString := trim(Excel.WorkSheets[1].Cells[iRow,iCol].value);
Fields[1].AsString := trim(Excel.WorkSheets[1].Cells[iRow,iCol+1].value);
Fields[2].Asstring := trim(Excel.WorkSheets[1].Cells[iRow,iCol+2].value);
Fields[3].Asstring := trim(Excel.WorkSheets[1].Cells[iRow,iCol+3].value);
Fields[4].AsString := trim(Excel.WorkSheets[1].Cells[iRow,iCol+4].value);
Fields[5].Asstring := trim(Excel.WorkSheets[1].Cells[iRow,iCol+5].value);
Fields[6].Asstring := trim(Excel.WorkSheets[1].Cells[iRow,iCol+6].value);
Fields[7].AsString := trim(Excel.WorkSheets[1].Cells[iRow,iCol+7].value);
Fields[8].Asstring := trim(Excel.WorkSheets[1].Cells[iRow,iCol+8].value);
Fields[9].Asstring := trim(Excel.WorkSheets[1].Cells[iRow,iCol+9].value);
Fields[10].AsString := trim(Excel.WorkSheets[1].Cells[iRow,iCol+10].value);
Fields[11].AsString := trim(Excel.WorkSheets[1].Cells[iRow,iCol+11].value);
iRow := iRow + 1;
statusbar1.Panels[0].Text:='导入记录:'+inttostr(iRow-1)+'条';
end;
end;
Excel.Quit;
ADOQuery1.UpdateStatus ;
except
Application.MessageBox('导入数据出错!请检查文件的格式是否正确!', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Excel.Quit;
end;
MessageBox(GetActiveWindow(), '数据导入成功!', '提示', MB_OK +
MB_ICONWARNING);
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货