欢迎各位兄弟 发布技术文章
这里的技术是共享的
set_time_limit(0); //设置页面等待时间 $file_arr = upload_excel(); $type = $file_arr['excel']['ext']; $uploadfile = "./Public/".$file_arr['excel']['savepath'].$file_arr['excel']['savename']; if ($uploadfile) { require './ThinkPHP/Library/Vendor/PHPExcel/PHPExcel/IOFactory.php'; if($type=='xlsx'||$type=='xls' ){ $reader = \PHPExcel_IOFactory::createReader('Excel2007'); // 读取 excel 文档 }else if( $type=='csv' ){ $reader = \PHPExcel_IOFactory::createReader('CSV'); // 读取 excel 文档 }else{ die('Not supported file types!'); } $PHPExcel = $reader->load($uploadfile); // 文档名称 $objWorksheet = $PHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); // 取得总行数 $highestColumn = $objWorksheet->getHighestColumn(); // 取得总列数 $arr = array(1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => 'E', 6 => 'F', 7 => 'G', 8 => 'H', 9 => 'I', 10 => 'J', 11 => 'K', 12 => 'L', 13 => 'M', 14 => 'N', 15 => 'O', 16 => 'P', 17 => 'Q', 18 => 'R', 19 => 'S', 20 => 'T', 21 => 'U', 22 => 'V', 23 => 'W', 24 => 'X', 25 => 'Y', 26 => 'Z'); //echo $highestRow.$highestColumn; // 一次读取一列 $res = array(); for ($row = 2; $row <= $highestRow; $row++) { for ($column = 0; $arr[$column] != 'T'; $column++) { $val = $objWorksheet->getCellByColumnAndRow($column, $row)->getValue(); $res[$row-2][$column] = $val; } }