Maison >développement back-end >tutoriel php >PHP导入Excel文件
点此查看PHP导出Excel文件
PHPExcel导入文件步骤:
1.实例化excel读取对象
2.加载excel文件
全部加载
选择加载
3.读取excel文件
全部读取
逐行读取
代码:
<?phpheader ("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; $igetSheet($i)->toArray(); //读取数据到数组 var_dump($data);}*///逐行读取foreach($objPHPExcel->getWorkSheetIterator() as $sheet){ foreach($sheet->getRowIterator() as $row){ if($row->getRowIndex() getCellIterator() as $cell) { $data = $cell->getValue(); echo $data.' '; } echo '<br>'; } echo '<br><hr>';}
版权声明:本文为博主原创文章,未经博主允许不得转载。