| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** Error reporting */ | 
					
						
							|  |  |  | error_reporting(E_ALL); | 
					
						
							| 
									
										
										
										
											2012-08-05 22:03:45 +00:00
										 |  |  | ini_set('display_errors', TRUE); | 
					
						
							|  |  |  | ini_set('display_startup_errors', TRUE); | 
					
						
							|  |  |  | date_default_timezone_set('Europe/London'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />'); | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | date_default_timezone_set('Europe/London'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * PHPExcel | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-05-02 22:50:37 +00:00
										 |  |  |  * Copyright (c) 2006 - 2015 PHPExcel | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							|  |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License along with this library; if not, write to the Free Software | 
					
						
							|  |  |  |  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @category   PHPExcel | 
					
						
							|  |  |  |  * @package    PHPExcel | 
					
						
							| 
									
										
										
										
											2015-05-02 22:50:37 +00:00
										 |  |  |  * @copyright  Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  |  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL | 
					
						
							| 
									
										
										
										
											2012-07-27 11:22:47 +00:00
										 |  |  |  * @version    ##VERSION##, ##DATE##
 | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** PHPExcel */ | 
					
						
							| 
									
										
										
										
											2013-07-10 11:33:04 +00:00
										 |  |  | require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; | 
					
						
							| 
									
										
										
										
											2013-04-21 15:27:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | $objPHPExcel = new PHPExcel(); | 
					
						
							|  |  |  | $objWorksheet = $objPHPExcel->getActiveSheet(); | 
					
						
							|  |  |  | $objWorksheet->fromArray( | 
					
						
							|  |  |  | 	array( | 
					
						
							|  |  |  | 		array('',	2010,	2011,	2012), | 
					
						
							|  |  |  | 		array('Q1',   12,   15,		21), | 
					
						
							|  |  |  | 		array('Q2',   56,   73,		86), | 
					
						
							|  |  |  | 		array('Q3',   52,   61,		69), | 
					
						
							|  |  |  | 		array('Q4',   30,   32,		0), | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-24 12:34:57 +00:00
										 |  |  | //	Set the Labels for each data series we want to plot
 | 
					
						
							| 
									
										
										
										
											2012-08-01 16:25:10 +00:00
										 |  |  | //		Datatype
 | 
					
						
							|  |  |  | //		Cell reference for data
 | 
					
						
							|  |  |  | //		Format Code
 | 
					
						
							|  |  |  | //		Number of datapoints in series
 | 
					
						
							|  |  |  | //		Data values
 | 
					
						
							|  |  |  | //		Data Marker
 | 
					
						
							| 
									
										
										
										
											2014-05-29 19:45:21 +00:00
										 |  |  | $dataSeriesLabels = array( | 
					
						
							| 
									
										
										
										
											2012-10-16 12:39:59 +00:00
										 |  |  | 	new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1),	//	2010
 | 
					
						
							|  |  |  | 	new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1),	//	2011
 | 
					
						
							|  |  |  | 	new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1),	//	2012
 | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | //	Set the X-Axis Labels
 | 
					
						
							| 
									
										
										
										
											2012-08-01 16:25:10 +00:00
										 |  |  | //		Datatype
 | 
					
						
							|  |  |  | //		Cell reference for data
 | 
					
						
							|  |  |  | //		Format Code
 | 
					
						
							|  |  |  | //		Number of datapoints in series
 | 
					
						
							|  |  |  | //		Data values
 | 
					
						
							|  |  |  | //		Data Marker
 | 
					
						
							| 
									
										
										
										
											2012-06-24 12:34:57 +00:00
										 |  |  | $xAxisTickValues = array( | 
					
						
							| 
									
										
										
										
											2012-10-16 12:39:59 +00:00
										 |  |  | 	new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4),	//	Q1 to Q4
 | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2012-06-24 12:34:57 +00:00
										 |  |  | //	Set the Data values for each data series we want to plot
 | 
					
						
							| 
									
										
										
										
											2012-08-01 16:25:10 +00:00
										 |  |  | //		Datatype
 | 
					
						
							|  |  |  | //		Cell reference for data
 | 
					
						
							|  |  |  | //		Format Code
 | 
					
						
							|  |  |  | //		Number of datapoints in series
 | 
					
						
							|  |  |  | //		Data values
 | 
					
						
							|  |  |  | //		Data Marker
 | 
					
						
							| 
									
										
										
										
											2012-06-24 12:34:57 +00:00
										 |  |  | $dataSeriesValues = array( | 
					
						
							| 
									
										
										
										
											2012-10-16 12:39:59 +00:00
										 |  |  | 	new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4), | 
					
						
							|  |  |  | 	new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4), | 
					
						
							|  |  |  | 	new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4), | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //	Build the dataseries
 | 
					
						
							|  |  |  | $series = new PHPExcel_Chart_DataSeries( | 
					
						
							| 
									
										
										
										
											2012-08-25 13:40:25 +00:00
										 |  |  | 	PHPExcel_Chart_DataSeries::TYPE_AREACHART,				// plotType
 | 
					
						
							|  |  |  | 	PHPExcel_Chart_DataSeries::GROUPING_PERCENT_STACKED,	// plotGrouping
 | 
					
						
							|  |  |  | 	range(0, count($dataSeriesValues)-1),					// plotOrder
 | 
					
						
							| 
									
										
										
										
											2014-05-29 19:45:21 +00:00
										 |  |  | 	$dataSeriesLabels,										// plotLabel
 | 
					
						
							| 
									
										
										
										
											2012-08-25 13:40:25 +00:00
										 |  |  | 	$xAxisTickValues,										// plotCategory
 | 
					
						
							|  |  |  | 	$dataSeriesValues										// plotValues
 | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //	Set the series in the plot area
 | 
					
						
							| 
									
										
										
										
											2014-05-29 19:45:21 +00:00
										 |  |  | $plotArea = new PHPExcel_Chart_PlotArea(NULL, array($series)); | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | //	Set the chart legend
 | 
					
						
							| 
									
										
										
										
											2012-10-16 12:39:59 +00:00
										 |  |  | $legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_TOPRIGHT, NULL, false); | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-02 11:06:48 +00:00
										 |  |  | $title = new PHPExcel_Chart_Title('Test %age-Stacked Area Chart'); | 
					
						
							| 
									
										
										
										
											2012-06-24 12:34:57 +00:00
										 |  |  | $yAxisLabel = new PHPExcel_Chart_Title('Value ($k)'); | 
					
						
							| 
									
										
										
										
											2012-06-18 22:43:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | //	Create the chart
 | 
					
						
							|  |  |  | $chart = new PHPExcel_Chart( | 
					
						
							|  |  |  | 	'chart1',		// name
 | 
					
						
							| 
									
										
										
										
											2012-06-18 22:43:53 +00:00
										 |  |  | 	$title,			// title
 | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | 	$legend,		// legend
 | 
					
						
							| 
									
										
										
										
											2014-05-29 19:45:21 +00:00
										 |  |  | 	$plotArea,		// plotArea
 | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | 	true,			// plotVisibleOnly
 | 
					
						
							|  |  |  | 	0,				// displayBlanksAs
 | 
					
						
							| 
									
										
										
										
											2012-10-16 12:39:59 +00:00
										 |  |  | 	NULL,			// xAxisLabel
 | 
					
						
							| 
									
										
										
										
											2012-06-24 12:34:57 +00:00
										 |  |  | 	$yAxisLabel		// yAxisLabel
 | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //	Set the position where the chart should appear in the worksheet
 | 
					
						
							|  |  |  | $chart->setTopLeftPosition('A7'); | 
					
						
							|  |  |  | $chart->setBottomRightPosition('H20'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //	Add the chart to the worksheet
 | 
					
						
							|  |  |  | $objWorksheet->addChart($chart); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Save Excel 2007 file
 | 
					
						
							| 
									
										
										
										
											2012-08-05 22:03:45 +00:00
										 |  |  | echo date('H:i:s') , " Write to Excel2007 format" , EOL; | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); | 
					
						
							|  |  |  | $objWriter->setIncludeCharts(TRUE); | 
					
						
							|  |  |  | $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); | 
					
						
							| 
									
										
										
										
											2012-08-05 22:03:45 +00:00
										 |  |  | echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Echo memory peak usage
 | 
					
						
							| 
									
										
										
										
											2012-08-05 22:03:45 +00:00
										 |  |  | echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; | 
					
						
							| 
									
										
										
										
											2012-06-18 20:47:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Echo done
 | 
					
						
							| 
									
										
										
										
											2012-08-05 22:03:45 +00:00
										 |  |  | echo date('H:i:s') , " Done writing file" , EOL; | 
					
						
							|  |  |  | echo 'File has been created in ' , getcwd() , EOL; |