求大神给我注释一下

zenzhaoqin zenzhaoqin 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
var
Excel: OleVariant;
iRow,iCol : integer;
xlsFilename: string;
begin
OpenDialog1.Title := '请选择正确的excel文件';
OpenDialog1.Filter := 'Excel(*.xls)|*.xls';
if OpenDialog1.Execute then
begin
xlsFilename := OpenDialog1.FileName;
try
Excel := CreateOLEObject('Excel.Application');
except
Application.MessageBox('excel没有安装', '提示信息', MB_OK+MB_ICONASTERISK+MB_DEFBUTTON1+MB_APPLMODAL);
Exit;
end;
ADOQ1.Close;
ADOQ1.Open;
ADOQ1.Filtered := false;
Excel.Visible := false;
Excel.WorkBooks.Open(xlsFilename);
try
iRow := 2;
iCol := 1;
while trim(Excel.WorkSheets[1].Cells[iRow,iCol].value) <> '' do
begin
if ADOQ1.Locate('years',trim(Excel.WorkSheets[1].Cells[iRow,iCol].value),[loCaseInsensitive]) then
begin
if not ADOQ1.FieldByName('audit').AsBoolean then
begin
ADOQ1.Edit;
ADOQ1.FieldByName('quantity').Value := StrToFloat(trim(Excel.WorkSheets[1].Cells[iRow,iCol+6].value));
ADOQ1.Post;
end
else
begin
ADOQ1.Insert;
ADOQ1.FieldByName('years').Value := trim(Excel.WorkSheets[1].Cells[iRow,iCol].value);
ADOQ1.FieldByName('quantity').Value := StrToFloat(trim(Excel.WorkSheets[1].Cells[iRow,iCol+6].value));
ADOQ1.Post;
end;
end
else
begin
ADOQ1.Insert;;
ADOQ1.FieldByName('years').Value := trim(Excel.WorkSheets[1].Cells[iRow,iCol].value);
ADOQ1.FieldByName('quantity').Value := StrToFloat(trim(Excel.WorkSheets[1].Cells[iRow,iCol+6].value));
ADOQ1.Post;
end;

iRow := iRow + 1;
end;
Excel.Quit;
MessageDlg('数据导入完成!',mtInformation,[mbOk],0);
except
Excel.Quit;
raise;
end;
ADOQ1.Close;
ADOQ1.Open;

end;

end;
...全文
评论 8
收藏 已收藏
分享
返回顶部