优惠券订单及其他脚本

35chartrender.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. /**
  10. * PHPExcel
  11. *
  12. * Copyright (c) 2006 - 2015 PHPExcel
  13. *
  14. * This library is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU Lesser General Public
  16. * License as published by the Free Software Foundation; either
  17. * version 2.1 of the License, or (at your option) any later version.
  18. *
  19. * This library is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  22. * Lesser General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Lesser General Public
  25. * License along with this library; if not, write to the Free Software
  26. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  27. *
  28. * @category PHPExcel
  29. * @package PHPExcel
  30. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  31. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  32. * @version ##VERSION##, ##DATE##
  33. */
  34. /** Include path **/
  35. set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../Classes/');
  36. /** PHPExcel_IOFactory */
  37. include 'PHPExcel/IOFactory.php';
  38. // Change these values to select the Rendering library that you wish to use
  39. // and its directory location on your server
  40. $rendererName = PHPExcel_Settings::CHART_RENDERER_JPGRAPH;
  41. $rendererLibrary = 'jpgraph3.5.0b1/src/';
  42. $rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary;
  43. if (!PHPExcel_Settings::setChartRenderer(
  44. $rendererName,
  45. $rendererLibraryPath
  46. )) {
  47. die(
  48. 'NOTICE: Please set the $rendererName and $rendererLibraryPath values' .
  49. EOL .
  50. 'at the top of this script as appropriate for your directory structure'
  51. );
  52. }
  53. $inputFileType = 'Excel2007';
  54. $inputFileNames = 'templates/32readwrite*[0-9].xlsx';
  55. if ((isset($argc)) && ($argc > 1)) {
  56. $inputFileNames = array();
  57. for($i = 1; $i < $argc; ++$i) {
  58. $inputFileNames[] = dirname(__FILE__) . '/templates/' . $argv[$i];
  59. }
  60. } else {
  61. $inputFileNames = glob($inputFileNames);
  62. }
  63. foreach($inputFileNames as $inputFileName) {
  64. $inputFileNameShort = basename($inputFileName);
  65. if (!file_exists($inputFileName)) {
  66. echo date('H:i:s') , " File " , $inputFileNameShort , ' does not exist' , EOL;
  67. continue;
  68. }
  69. echo date('H:i:s') , " Load Test from $inputFileType file " , $inputFileNameShort , EOL;
  70. $objReader = PHPExcel_IOFactory::createReader($inputFileType);
  71. $objReader->setIncludeCharts(TRUE);
  72. $objPHPExcel = $objReader->load($inputFileName);
  73. echo date('H:i:s') , " Iterate worksheets looking at the charts" , EOL;
  74. foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
  75. $sheetName = $worksheet->getTitle();
  76. echo 'Worksheet: ' , $sheetName , EOL;
  77. $chartNames = $worksheet->getChartNames();
  78. if(empty($chartNames)) {
  79. echo ' There are no charts in this worksheet' , EOL;
  80. } else {
  81. natsort($chartNames);
  82. foreach($chartNames as $i => $chartName) {
  83. $chart = $worksheet->getChartByName($chartName);
  84. if (!is_null($chart->getTitle())) {
  85. $caption = '"' . implode(' ',$chart->getTitle()->getCaption()) . '"';
  86. } else {
  87. $caption = 'Untitled';
  88. }
  89. echo ' ' , $chartName , ' - ' , $caption , EOL;
  90. echo str_repeat(' ',strlen($chartName)+3);
  91. $jpegFile = '35'.str_replace('.xlsx', '.jpg', substr($inputFileNameShort,2));
  92. if (file_exists($jpegFile)) {
  93. unlink($jpegFile);
  94. }
  95. try {
  96. $chart->render($jpegFile);
  97. } catch (Exception $e) {
  98. echo 'Error rendering chart: ',$e->getMessage();
  99. }
  100. }
  101. }
  102. }
  103. $objPHPExcel->disconnectWorksheets();
  104. unset($objPHPExcel);
  105. }
  106. // Echo memory peak usage
  107. echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
  108. // Echo done
  109. echo date('H:i:s') , " Done rendering charts as images" , EOL;
  110. echo 'Image files have been created in ' , getcwd() , EOL;