优惠券订单及其他脚本

36chartreadwriteHTML.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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/36write*.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. $groupCount = $chart->getPlotArea()->getPlotGroupCount();
  92. if ($groupCount == 1) {
  93. $chartType = $chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType();
  94. echo ' ' , $chartType , EOL;
  95. } else {
  96. $chartTypes = array();
  97. for($i = 0; $i < $groupCount; ++$i) {
  98. $chartTypes[] = $chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType();
  99. }
  100. $chartTypes = array_unique($chartTypes);
  101. if (count($chartTypes) == 1) {
  102. $chartType = 'Multiple Plot ' . array_pop($chartTypes);
  103. echo ' ' , $chartType , EOL;
  104. } elseif (count($chartTypes) == 0) {
  105. echo ' *** Type not yet implemented' , EOL;
  106. } else {
  107. echo ' Combination Chart' , EOL;
  108. }
  109. }
  110. }
  111. }
  112. }
  113. $outputFileName = str_replace('.xlsx', '.html', basename($inputFileName));
  114. echo date('H:i:s') , " Write Tests to HTML file " , EOL;
  115. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
  116. $objWriter->setIncludeCharts(TRUE);
  117. $objWriter->save($outputFileName);
  118. echo date('H:i:s') , " File written to " , $outputFileName , EOL;
  119. $objPHPExcel->disconnectWorksheets();
  120. unset($objPHPExcel);
  121. }
  122. // Echo memory peak usage
  123. echo date('H:i:s') , ' Peak memory usage: ' , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
  124. // Echo done
  125. echo date('H:i:s') , " Done writing files" , EOL;
  126. echo 'Files have been created in ' , getcwd() , EOL;