public function readExcel(){ $allPath = '/home/examine\video/list.xls';
\think\Loader::import('extend.excel.PHPExcel', ROOT_PATH); $PHPExcel = new \PHPExcel(); $redis = new \app\common\service\Redis();
/* * 默认用excel2007读取excel,若格式不对,则用之前的版本进行读取 */ $PHPReader = new \PHPExcel_Reader_Excel2007(); if (!$PHPReader->canRead($allPath)) { $PHPReader = new \PHPExcel_Reader_Excel5(); if (!$PHPReader->canRead($allPath)) { echo 'no Excel';die; } }
$phpExcel = $PHPReader->load($allPath); $objWriter = new \PHPExcel_Writer_Excel5($PHPExcel); $currentSheet = $phpExcel->getSheet(0); //读取excel文件中的第一个工作表 $allColumn = $currentSheet->getHighestColumn(); //取得最大的列号 $allRow = $currentSheet->getHighestRow(); //取得一共有多少行 $excelResult = array(); //声明数组
//从第一行开始读取数据 $startRow = $redis->get('startRow') ? $redis->get('startRow')+1 : 2; $endRow = $startRow + 500; if($endRow >= $allRow){ $endRow = $allRow; } for ($j = $startRow; $j <= $endRow; $j++) { //从A列读取数据 for ($k = 'A'; $k <= $allColumn; $k++) { // 读取单元格 $excelResult[$j][] = (string)$phpExcel->getActiveSheet()->getCell("$k$j")->getValue(); } } dp($excelResult); }
|
请发表评论