首页 > 代码库 > NativeExcel 读取文件
NativeExcel 读取文件
class function T_EShopDataBill.ImportData(const AFileName: String; AList: T_EShopDataModelList; var AErr: string): Boolean;var Book: IXLSWorkbook; ws: IXLSWorksheet; i : Integer; nOrderIDRow,nTrackNoRow : Integer; obj : T_EShopDataModel; tmpIden,tmpTrackNo : String; sSql : String; tmpQry : TADOQuery;begin Book := TXLSWorkbook.Create ; try i := Book.Open(AFileName); ws := Book.WorkSheets[1]; if ws.UsedRange.Rows.Count = 0 then Exit; nOrderIDRow := 0; nTrackNoRow := 0; for I := 1 to ws.UsedRange.Rows[1].Count -1 do begin if nOrderIDRow = 0 then if CompareText( VarToStr( ws.UsedRange.Cells[1,i].Value),‘单据备注‘) = 0 then nOrderIDRow := i; if nTrackNoRow = 0 then if CompareText( VarToStr( ws.UsedRange.Cells[1,i].Value),‘运单编号‘) = 0 then nTrackNoRow := i; if (nOrderIDRow > 0 ) AND (nTrackNoRow > 0) then Break; end; // ShowInformationMsg(inttostr(nOrderIDRow)+‘ ‘+IntTostr(nTrackNoRow)); if (nOrderIDRow = 0) or (nTrackNoRow = 0) then Exit; for i := 2 to ws.UsedRange.Rows.Count do begin with ws.UsedRange do begin if VarIsNull(Cells[i,nTrackNoRow].Value) then Break; if VarIsNull(Cells[i,nOrderIDRow].Value) then Break; end; tmpTrackNo := ws.UsedRange.Cells[i,nTrackNoRow].Value; tmpIden := ws.UsedRange.Cells[i,nOrderIDRow].Value; if ( Trim(tmpTrackNo) = ‘‘) or (tmpIden = ‘‘) then begin Break; end; obj := T_EShopDataModel.Create; obj.fOrderID := tmpIden; obj.fTrackNo := tmpTrackNo; AList.List.Add(obj); end; finally Book.Close; end;end
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。