| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  |  * PhpSpreadsheet | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  |  * Copyright (c) 2006 - 2016 PhpSpreadsheet | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +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 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  |  * @category   PhpSpreadsheet | 
					
						
							|  |  |  |  * @copyright  Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) | 
					
						
							|  |  |  |  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  |  * @version    ##VERSION##, ##DATE##
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** Error reporting */ | 
					
						
							|  |  |  | error_reporting(E_ALL); | 
					
						
							| 
									
										
										
										
											2012-08-05 17:54:20 +00:00
										 |  |  | ini_set('display_errors', TRUE); | 
					
						
							|  |  |  | ini_set('display_startup_errors', TRUE); | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | date_default_timezone_set('Europe/London'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-05 17:54:20 +00:00
										 |  |  | define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | /** Include PhpSpreadsheet */ | 
					
						
							| 
									
										
										
										
											2015-05-26 20:21:05 +00:00
										 |  |  | require_once dirname(__FILE__) . '/../src/Bootstrap.php'; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | // Create new Spreadsheet object
 | 
					
						
							|  |  |  | echo date('H:i:s') , " Create new Spreadsheet object" , EOL; | 
					
						
							|  |  |  | $objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet(); | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 23:03:57 +00:00
										 |  |  | // Set document properties
 | 
					
						
							| 
									
										
										
										
											2012-08-05 17:54:20 +00:00
										 |  |  | echo date('H:i:s') , " Set document properties" , EOL; | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objPhpSpreadsheet->getProperties() | 
					
						
							| 
									
										
										
										
											2015-05-24 22:52:44 +00:00
										 |  |  |     ->setCreator("Maarten Balliauw") | 
					
						
							|  |  |  | 	->setLastModifiedBy("Maarten Balliauw") | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | 	->setTitle("PhpSpreadsheet Test Document") | 
					
						
							|  |  |  | 	->setSubject("PhpSpreadsheet Test Document") | 
					
						
							|  |  |  | 	->setDescription("Test document for PhpSpreadsheet, generated using PHP classes.") | 
					
						
							|  |  |  | 	->setKeywords("office PhpSpreadsheet php") | 
					
						
							| 
									
										
										
										
											2015-05-24 22:52:44 +00:00
										 |  |  | 	->setCategory("Test result file"); | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Add some data
 | 
					
						
							| 
									
										
										
										
											2012-08-05 17:54:20 +00:00
										 |  |  | echo date('H:i:s') , " Add some data" , EOL; | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objPhpSpreadsheet->setActiveSheetIndex(0) | 
					
						
							| 
									
										
										
										
											2015-05-24 22:52:44 +00:00
										 |  |  |     ->setCellValue('A1', 'Hello') | 
					
						
							|  |  |  |     ->setCellValue('B2', 'world!') | 
					
						
							|  |  |  |     ->setCellValue('C1', 'Hello') | 
					
						
							|  |  |  |     ->setCellValue('D2', 'world!'); | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Miscellaneous glyphs, UTF-8
 | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objPhpSpreadsheet->setActiveSheetIndex(0) | 
					
						
							| 
									
										
										
										
											2015-05-24 22:52:44 +00:00
										 |  |  |     ->setCellValue('A4', 'Miscellaneous glyphs') | 
					
						
							|  |  |  |     ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-18 12:48:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objPhpSpreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2015-05-24 22:52:44 +00:00
										 |  |  |     ->setCellValue('A8',"Hello\nWorld"); | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objPhpSpreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2015-05-24 22:52:44 +00:00
										 |  |  |     ->getRowDimension(8) | 
					
						
							|  |  |  |     ->setRowHeight(-1); | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objPhpSpreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2015-05-24 22:52:44 +00:00
										 |  |  |     ->getStyle('A8') | 
					
						
							|  |  |  |     ->getAlignment() | 
					
						
							|  |  |  |     ->setWrapText(true); | 
					
						
							| 
									
										
										
										
											2012-12-18 12:48:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-06 16:08:37 +00:00
										 |  |  | $value = "-ValueA\n-Value B\n-Value C"; | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objPhpSpreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2015-12-06 16:08:37 +00:00
										 |  |  |     ->setCellValue('A10', $value); | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objPhpSpreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2015-12-06 16:08:37 +00:00
										 |  |  |     ->getRowDimension(10) | 
					
						
							|  |  |  |     ->setRowHeight(-1); | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objPhpSpreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2015-12-06 16:08:37 +00:00
										 |  |  |     ->getStyle('A10') | 
					
						
							|  |  |  |     ->getAlignment() | 
					
						
							|  |  |  |     ->setWrapText(true); | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objPhpSpreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2015-12-06 16:08:37 +00:00
										 |  |  |     ->getStyle('A10') | 
					
						
							|  |  |  |     ->setQuotePrefix(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-12 23:03:57 +00:00
										 |  |  | // Rename worksheet
 | 
					
						
							| 
									
										
										
										
											2012-08-05 17:54:20 +00:00
										 |  |  | echo date('H:i:s') , " Rename worksheet" , EOL; | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objPhpSpreadsheet->getActiveSheet() | 
					
						
							| 
									
										
										
										
											2015-05-24 22:52:44 +00:00
										 |  |  |     ->setTitle('Simple'); | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Set active sheet index to the first sheet, so Excel opens this as the first sheet
 | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objPhpSpreadsheet->setActiveSheetIndex(0); | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Save Excel 2007 file
 | 
					
						
							| 
									
										
										
										
											2012-08-05 17:54:20 +00:00
										 |  |  | echo date('H:i:s') , " Write to Excel2007 format" , EOL; | 
					
						
							| 
									
										
										
										
											2012-11-28 21:30:58 +00:00
										 |  |  | $callStartTime = microtime(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007'); | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | $objWriter->save(str_replace('.php', '.xlsx', __FILE__)); | 
					
						
							| 
									
										
										
										
											2012-11-28 21:30:58 +00:00
										 |  |  | $callEndTime = microtime(true); | 
					
						
							|  |  |  | $callTime = $callEndTime - $callStartTime; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-05 17:54:20 +00:00
										 |  |  | echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; | 
					
						
							| 
									
										
										
										
											2012-11-28 21:30:58 +00:00
										 |  |  | echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; | 
					
						
							|  |  |  | // Echo memory usage
 | 
					
						
							|  |  |  | echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Save Excel 95 file
 | 
					
						
							| 
									
										
										
										
											2012-08-05 17:54:20 +00:00
										 |  |  | echo date('H:i:s') , " Write to Excel5 format" , EOL; | 
					
						
							| 
									
										
										
										
											2012-11-28 21:30:58 +00:00
										 |  |  | $callStartTime = microtime(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-16 23:06:51 +00:00
										 |  |  | $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel5'); | 
					
						
							| 
									
										
										
										
											2012-07-13 15:58:44 +00:00
										 |  |  | $objWriter->save(str_replace('.php', '.xls', __FILE__)); | 
					
						
							| 
									
										
										
										
											2012-11-28 21:30:58 +00:00
										 |  |  | $callEndTime = microtime(true); | 
					
						
							|  |  |  | $callTime = $callEndTime - $callStartTime; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-05 17:54:20 +00:00
										 |  |  | echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; | 
					
						
							| 
									
										
										
										
											2012-11-28 21:30:58 +00:00
										 |  |  | echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL; | 
					
						
							|  |  |  | // Echo memory usage
 | 
					
						
							|  |  |  | echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Echo memory peak usage
 | 
					
						
							| 
									
										
										
										
											2012-08-05 17:54:20 +00:00
										 |  |  | echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; | 
					
						
							| 
									
										
										
										
											2010-08-26 19:14:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Echo done
 | 
					
						
							| 
									
										
										
										
											2012-08-05 17:54:20 +00:00
										 |  |  | echo date('H:i:s') , " Done writing files" , EOL; | 
					
						
							|  |  |  | echo 'Files have been created in ' , getcwd() , EOL; |