PHP导入Excel文件

WBOY
Release: 2016-06-23 13:27:42
Original
1385 people have browsed it

点此查看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>';}
Copy after login

帮助文档:


版权声明:本文为博主原创文章,未经博主允许不得转载。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template