php导入excelphp使用phpexcel导入excel文件
时间:2021-07-01 10:21:17
帮助过:20人阅读
//载入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();
//获取列数 - //by bbs.it-home.org
- $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 ' '; - print_r($data);
- echo '';
|