nexcel 读取 excel

procedure TfrmUserV3.ImportUser(const AFileName: string);
var
  book :IXLSWorkBook;
  ws : IXLSWorkSheet;
  i,j : Integer;
  v : Variant;

  obj : T_LoginUser;
  objList : T_LoginUserInf;

  sCode,sName,sPwd,sGroup : string;
begin
   book := TXLSWorkbook.Create;

   objList := T_LoginUserInf.Create;
   try
      i := book.Open(AFileName);
      ws := book.WorkSheets[1];
      if ws.UsedRange.Rows.Count = 0  then
        Exit;
      for i := 2 to ws.UsedRange.Rows.Count -1 do
      begin
         if VarIsNull(ws.UsedRange.Rows[i].Item[1].Value) then
            Continue;

         sCode := ws.UsedRange.Rows[i].item[1].Value;
         with ws.UsedRange.Rows[i] do
         begin
           sName := Item[2].Value;
           sPwd := Item[3].Value;
           sGroup := Item[4].Value;
         end;

         if Trim(sCode)  <> '' then
         begin
             obj := T_LoginUser.Create;
             obj.fUserID := sCode;
             obj.fUserName := sName;
             obj.fPassword := sPwd;
             obj.fGroupID := sGroup;
             objList.fList.Add(obj);
         end;
      end;

      if objList.fList.List.Count > 0  then
      begin
          objList.AddUser(MyValue.UniConn);
      end;
   finally
      book := nil;
      objList.Free;
   end;
原文地址:https://www.cnblogs.com/starluck/p/6122981.html