PHP读取excel
Posted 荷西呀
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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‘);
}
以上是关于PHP读取excel的主要内容,如果未能解决你的问题,请参考以下文章