PHP-导入excel实例

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

<?php
/**
* composer 安装 composer require phpoffice/phpexcel
*/
/**
 * 导入绑定
 * @throws PHPExcel_Exception
 * @throws PHPExcel_Reader_Exception
 * User: Dh106
 * Date: 2018/8/9
 * Time: 16:14
 */
public function importBind()
{
     $name = request()->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')]);
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 去了趟南京,车在立交桥上开往机场,随手拍了这张日落。只拍了一张,有点可惜。
    林镇超Elvis阅读 208评论 0 0
  • 初次了解于娟还是在网上,当时介绍的是复旦女教师32岁乳腺癌去世。不免唏嘘,英年早逝!紧接着就是一些介绍不要熬...
    紫粉色阅读 916评论 0 2
  • 下了汽车,我抱着滚蛋急急地跑到站牌下,抬头看了看天,无奈地从包里翻出一把遮阳伞。 明明是在出发前查过天气的,可预测...
    Sharl阅读 151评论 0 1