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[]; if ws.UsedRange.Rows.Count = then
Exit; nOrderIDRow := ;
nTrackNoRow := ;
for I := to ws.UsedRange.Rows[].Count - do
begin
if nOrderIDRow = then
if CompareText( VarToStr( ws.UsedRange.Cells[,i].Value),'单据备注') = then
nOrderIDRow := i; if nTrackNoRow = then
if CompareText( VarToStr( ws.UsedRange.Cells[,i].Value),'运单编号') = then
nTrackNoRow := i; if (nOrderIDRow > ) AND (nTrackNoRow > ) then
Break;
end; // ShowInformationMsg(inttostr(nOrderIDRow)+' '+IntTostr(nTrackNoRow));
if (nOrderIDRow = ) or (nTrackNoRow = ) then
Exit; for i := 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