説明なし

40duplicateStyle.php 1.7KB

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