PHPExcel导入文件步骤:
1.实例化excel读取对象
2.加载excel文件
全部加载
选择加载
3.读取excel文件
全部读取
逐行读取
代码:
<?php header("Content-Type:text/html;charset=utf-8"); $dir = dirname(__FILE__); require $dir.'/PHPExcel/IOFactory.php'; $filename = $dir."/export.xls"; //部分加载 $fileType = PHPExcel_IOFactory::identify($filename); $objReader = PHPExcel_IOFactory::createReader($fileType); $sheetName = array("Worksheet 1"); $objReader->setLoadSheetsOnly($sheetName); $objPHPExcel = $objReader->load($filename); //全部加载 //$objPHPExcel = PHPExcel_IOFactory::load($filename); //加载文件 //全部读取 /* $sheetCount = $objPHPExcel->getSheetCount(); for($i=0; $i<$sheetCount; $i++){ $data = $objPHPExcel->getSheet($i)->toArray(); //读取数据到数组 var_dump($data); }*/ //逐行读取 foreach($objPHPExcel->getWorkSheetIterator() as $sheet){ foreach($sheet->getRowIterator() as $row){ if($row->getRowIndex() < 2) continue; //忽略第一行 foreach ($row->getCellIterator() as $cell) { $data = $cell->getValue(); echo $data.' '; } echo '<br/>'; } echo '<br/><hr/>'; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/qq_20480611/article/details/48004787