function getExcelData($filename) { $objReader = PHPExcel_IOFactory::createReader('Excel5'); $objReader->setReadDataOnly(true); $objPHPExcel = $objReader->load($filename); $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); $highestColumn = $objWorksheet->getHighestColumn(); $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); if($highestRow==0) return; for($row = 1; $row <= $highestRow; $row++) { for($col = 0; $col < $highestColumnIndex; $col++) { $excelData[$row][] = (string)$objWorksheet->getCellByColumnAndRow($col, $row)->getValue(); } } return $excelData; }结果发现有些excel文件上传读取失败,直接服务器500。检查看了下,原来php excel在不同的版本,实例化类是不一样的。
$objReader = PHPExcel_IOFactory::createReader('Excel2007'); if(!$objReader->canRead($filename)) { $objReader = PHPExcel_IOFactory::createReader('Excel5'); if(!$objReader->canRead($filename)) return; }
小记,以防他日忘记。
已有0条评论