码迷,mamicode.com
首页 > Web开发 > 详细

PHP读取excel

时间:2018-06-12 16:09:49      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:load   ext   ict   har   bank   后缀   foreach   pex   sheet   

$file = ‘‘;//文件名称

$file_ext = explode(‘.‘,$file);
$file_ext = $file_ext[1];
$data[‘file_ext‘] = $file_ext;
require ‘../application/helpers/PHPExcel.php‘;

//判断后缀
if($file_ext === ‘xls‘){
      $objReader = new PHPExcel_Reader_Excel5();
}
if($file_ext === ‘xlsx‘){
      $objReader = new PHPExcel_Reader_Excel2007();
}
$candfile_name = "./canddata/".$time."/".time()."/cand_picture/cands/".$file;
$data[‘cand_file‘] = $candfile_name;
$objPHPExcel = $objReader->load($candfile_name); //指定的文件
$sheet = $objPHPExcel->getSheet(0);     //指定的表
$highestRow = $sheet->getHighestRow(); // 取得总行数
$highestColumn = $sheet->getHighestColumn(); // 取得总列数
//从第2行开始读起
for( $i=2; $i <= $highestRow; $i++ ){
       //显示各列
       for( $j=‘A‘; $j<=‘I‘; $j++ ){
               if($j==‘I‘){
                      $arr[$i][$j] = $sheet->getCell($j.$i)->getValue();
               }else{
                      $arr[$i][$j] = replace_special_char($sheet->getCell($j.$i)->getValue());
               }
       }
}
foreach ( $arr as $key => $value ) {
       $cands[$key][‘bank_one‘] = trim(replace_special_char($value[‘B‘]));
       $cands[$key][‘bank_two‘] = trim(replace_special_char($value[‘C‘]));
       $cands[$key][‘cand_name‘] = trim(replace_special_char($value[‘D‘]));
       $cands[$key][‘sex‘] = trim(replace_special_char($value[‘E‘]));
       $cands[$key][‘cand_card‘] = trim(replace_special_char($value[‘F‘]));
       $cands[$key][‘cand_iphone‘] = trim(replace_special_char($value[‘G‘]));
       $cands[$key][‘logname‘] = trim(replace_special_char($value[‘H‘]));
       $cands[$key][‘card‘] = trim(replace_special_char($value[‘I‘]));
       $cands[$key][‘creat_time‘] = date(‘Y-m-d H:i:s‘);
}

PHP读取excel

标签:load   ext   ict   har   bank   后缀   foreach   pex   sheet   

原文地址:https://www.cnblogs.com/wanghaodong/p/9172946.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!