16 PHPExcel使用

这是用来读取上传的excel文件的,至于如何生成我还没细细研究,大家可以baidu
下载地址http://phpexcel.codeplex.com/

<?php
		if ($_FILES["uploadFile"]["size"] < 20000000){
	  		if ($_FILES["uploadFile"]["error"] > 0){
	    		echo "Return Code: " . $_FILES["uploadFile"]["error"] . "<br />";
	    	}else{
					$uploadFileTime	=	time();
		      		move_uploaded_file($_FILES["uploadFile"]["tmp_name"],"temp_excel/".$uploadFileTime.".xls");
	    	}
	   }
 
		require_once 'Classes/PHPExcel.php';
		$fileName 	= $uploadFileTime.".xls";
		$path 		= 'temp_excel/';
		$filePath 	= $path . $fileName;
		$PHPExcel 	= new PHPExcel ();
		$PHPReader 	= new PHPExcel_Reader_Excel2007 ();
		PHPExcel_CachedObjectStorageFactory::cache_to_discISAM;  
		if (! $PHPReader->canRead ( $filePath )) {
			$PHPReader = new PHPExcel_Reader_Excel5 ();
			if (! $PHPReader->canRead ( $filePath )) {
				echo 'Read Excel Failed! Please Contact Admin';
			}
		}
		$PHPExcel 		= $PHPReader->load ( $filePath );
		$currentSheet 	= $PHPExcel->getSheet ( 0 );
		// get cols
		$allColumn 		= $currentSheet->getHighestColumn ();
		// get rows
		$allRow 		= $currentSheet->getHighestRow () ;	
		for($currentRow = 1; $currentRow <= $allRow; $currentRow ++) {
			for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
				$address = $currentColumn . $currentRow;
				$destArr[]	=	$currentSheet->getCell ($address)->getValue ();
			}
		}
?>

Related posts:

Leave a Reply

Your email address will not be published.