Home  >  Article  >  php教程  >  读取Excel

读取Excel

PHP中文网
PHP中文网Original
2016-05-25 17:04:581709browse

php代码

	/* Report all errors except E_NOTICE */
	error_reporting(E_ALL^E_NOTICE);
	$filename = $_GET['filename'];
	$xlsPath = $filename; //指定要读取的exls路径 
	//$type = 'Excel2007'; //设置要解析的Excel类型 Excel5(2003或以下版本)或Excel2007
	$type = 'Excel5';
	//引入excel类
	include 'load.php';
	include 'Classes/PHPExcel.php';			
	include 'Classes/PHPExcel/IOFactory.php';
	$xlsReader = PHPExcel_IOFactory::createReader($type);  
	$xlsReader->setReadDataOnly(true);
	$xlsReader->setLoadSheetsOnly(true);
	$Sheets = $xlsReader->load($xlsPath);

	//开始读取
	$Sheet = $Sheets->getSheet(0)->toArray(); //读取第一个工作表(注意编号从0开始) 如果读取多个可以做一个循环0,1,2,3....

	//得到二维数组,每个小数组是excel表格内容的一行 里面包含此行的每列的数据  
	echo '';
	echo '';
	echo '数量订单总数';
	$data = array();
	for($i=2;$i0){
		    $info[$val['name']] = ++$sum;
		}else{
		    $info[$val['name']] = --$sum;
		}
		
	}
	foreach($info as $key=>$val){
		echo "".$key."".$val."";
	}		            		        	
			
Statement:
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
Previous article:把字符内容转换为二进制Next article:PHP截取字符串