<?php //载入PHPExcel类 include(dirname(__FILE__).'/phpexcel/PHPExcel.php'); $Obj = new PHPExcel_Reader_Excel5(); $Obj->setReadDataOnly(true); //读取demo.xls文件 $phpExcel = $Obj->load(dirname(__FILE__).'/output.xls'); //获取当前活动sheet $objWorksheet = $phpExcel->getActiveSheet(); //获取行数 $highestRow = $objWorksheet->getHighestRow(); //获取列数 $highestColumn = $objWorksheet->getHighestColumn(); $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); //循环输出数据 $data = array(); for($row = 1; $row <= $highestRow; ++$row) { for($col = 0; $col < $highestColumnIndex; ++$col) { $val = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue(); $data[$row][$col] = trim($val); } } echo '<pre>'; print_r($data); echo '</pre>';
但是这种方式有缺陷,老版本的excel有个数据上限,最多65536行数据,这时我们就无法通过excel来实现大数据的导出, 但我估计也没几个有这么我数据吧,当然如果有可以考虑使用csv来操作