• PHP读取excel


    $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');
    }

  • 相关阅读:
    jq function return value
    danci4
    danci3
    danci2
    项目总结 和语言总结。
    vm 安装 ox 10.13
    ios 异步和多线程
    ios 语法问题 全局变量。
    mvc
    object-c 之autolayout
  • 原文地址:https://www.cnblogs.com/wanghaodong/p/9172946.html
Copyright © 2020-2023  润新知