header("Content-Type:text/html;charset=utf-8"); $dir = dirname(__FILE__); require $dir . DIRECTORY_SEPARATOR . "phpexcel/PHPExcel/IOFactory.php"; $filename = $dir . DIRECTORY_SEPARATOR . "data/能源计量数据直报/电/重点用户监控数据2016-01-16.xls"; $inputFileType = PHPExcel_IOFactory::identify($filename); $objReader = PHPExcel_IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($filename); $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); //$highestColumn = $objWorksheet->getHighestColumn(); $arr = array(5 => 'E', 7 => 'G', 8 => 'H', 15 => 'O', 16 => 'P'); $res = array(); for ($row = 2; $row <= $highestRow; $row++) { for ($column = 0; $column < count($arr); $column++) { $var = $objWorksheet->getCellByColumnAndRow($column, $row)->getValue(); $res[$row - 2][$column] = $var; } } print_r($res);
但是报错:
Fatal error: Uncaught PHPExcel_Reader_Exception: Could not open H:\Users\LiuQi\PhpstormProjects\Study\jxsenergy\data/能源计量数据直报/电/重点用户监控数据2016-01-16.xls for reading! File does not exist. in H:\Users\LiuQi\PhpstormProjects\Study\jxsenergy\phpexcel\PHPExcel\Reader\Excel5.php:433 Stack trace: #0 H:\Users\LiuQi\PhpstormProjects\Study\jxsenergy\phpexcel\PHPExcel\IOFactory.php(269): PHPExcel_Reader_Excel5->canRead('H:\\Users\\LiuQi\\...') #1 H:\Users\LiuQi\PhpstormProjects\Study\jxsenergy\phpexcel\PHPExcel\IOFactory.php(206): PHPExcel_IOFactory::createReaderForFile('H:\\Users\\LiuQi\\...') #2 H:\Users\LiuQi\PhpstormProjects\Study\jxsenergy\import.php(13): PHPExcel_IOFactory::identify('H:\\Users\\LiuQi\\...') #3 {main} thrown in H:\Users\LiuQi\PhpstormProjects\Study\jxsenergy\phpexcel\PHPExcel\Reader\Excel5.php on line 433
解决了吗,我也是这个错误