| 1 |
<?php |
| 2 |
/** Error reporting */ |
| 3 |
error_reporting(E_ALL); |
| 4 |
ini_set('display_errors', TRUE); |
| 5 |
ini_set('display_startup_errors', TRUE); |
| 6 |
date_default_timezone_set('Europe/London'); |
| 7 |
|
| 8 |
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />'); |
| 9 |
|
| 10 |
date_default_timezone_set('Europe/London'); |
| 11 |
|
| 12 |
/** Include PHPExcel */ |
| 13 |
require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; |
| 14 |
|
| 15 |
echo date('H:i:s') , " Create new PHPExcel object" , EOL; |
| 16 |
$objPHPExcel = new PHPExcel(); |
| 17 |
$worksheet = $objPHPExcel->getActiveSheet(); |
| 18 |
|
| 19 |
echo date('H:i:s') , " Create styles array" , EOL; |
| 20 |
$styles = array(); |
| 21 |
for ($i = 0; $i < 10; $i++) { |
| 22 |
$style = new PHPExcel_Style(); |
| 23 |
$style->getFont()->setSize($i + 4); |
| 24 |
$styles[] = $style; |
| 25 |
} |
| 26 |
|
| 27 |
echo date('H:i:s') , " Add data (begin)" , EOL; |
| 28 |
$t = microtime(true); |
| 29 |
for ($col = 0; $col < 50; $col++) { |
| 30 |
for ($row = 0; $row < 100; $row++) { |
| 31 |
$str = ($row + $col); |
| 32 |
$style = $styles[$row % 10]; |
| 33 |
$coord = PHPExcel_Cell::stringFromColumnIndex($col) . ($row + 1); |
| 34 |
$worksheet->setCellValue($coord, $str); |
| 35 |
$worksheet->duplicateStyle($style, $coord); |
| 36 |
} |
| 37 |
} |
| 38 |
$d = microtime(true) - $t; |
| 39 |
echo date('H:i:s') , " Add data (end), time: " . round($d, 2) . " s", EOL; |
| 40 |
|
| 41 |
|
| 42 |
echo date('H:i:s') , " Write to Excel2007 format" , EOL; |
| 43 |
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); |
| 44 |
$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); |
| 45 |
echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL; |
| 46 |
|
| 47 |
|
| 48 |
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; |
| 49 |
|
| 50 |
echo date('H:i:s') , " Done writing file" , EOL; |
| 51 |
echo 'File has been created in ' , getcwd() , EOL; |
| 52 |
|