PHP-导入excel实例

导入excel或者其他文件其方式方法都是一样的,可以在上传的对象加入一些数据类型的限制,那样就可以限制上传的是什么样的文件了,这里只做实例,更多的相知可以去学习和使用.

file('file');
     $info = $name->move(ROOT_PATH . 'public' . DS . 'uploads'. DS . 'file');
     $file = $info->getPathname();
     $objPHPExcel = PHPExcel_IOFactory::load($file);
     $objPHPExcel->setActiveSheetIndex(0);
     $sheet=$objPHPExcel->getSheet(0);
     $highrow = $sheet->getHighestRow();
     for ($i=2;$i<=$highrow;$i++) {
         $userteamtitle = (string)$sheet->getCellByColumnAndRow(3,$i)->getValue();
         if(empty($userteamtitle)) {
             break;
         }
         $cardsn = trim((string)$sheet->getCellByColumnAndRow(1,$i)->getValue(),' ');
         $cardsnONE = substr($cardsn,0,1);
         $cardsn = $cardsnONE=='y'?$cardsn:substr($cardsn,2);
         $username = (string)$sheet->getCellByColumnAndRow(2,$i)->getValue();
         $teamid = $this->logicIdentityTeam->getTeamIdByName($userteamtitle);
         $data = [
             'user_name' => $username,
              'user_team' => $teamid,
             'bind_time' => time(),
             'update_time' => time(),
         ];
         $this->logicIdentityCard->bindCardByImport($cardsn,$data);
     }
     $this->ajaxJump([RESULT_SUCCESS,'导入成功',url('identitycard/cardList')]);
}

你可能感兴趣的:(PHP-导入excel实例)