Geen omschrijving

18extendedcalculation.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (C) 2006 - 2014 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel
  23. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /** Error reporting */
  28. error_reporting(E_ALL);
  29. ini_set('display_errors', TRUE);
  30. ini_set('display_startup_errors', TRUE);
  31. date_default_timezone_set('Europe/London');
  32. define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
  33. date_default_timezone_set('Europe/London');
  34. /** PHPExcel */
  35. require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
  36. // List functions
  37. echo date('H:i:s') . " List implemented functions\n";
  38. $objCalc = PHPExcel_Calculation::getInstance();
  39. print_r($objCalc->listFunctionNames());
  40. // Create new PHPExcel object
  41. echo date('H:i:s') . " Create new PHPExcel object\n";
  42. $objPHPExcel = new PHPExcel();
  43. // Add some data, we will use some formulas here
  44. echo date('H:i:s') . " Add some data\n";
  45. $objPHPExcel->getActiveSheet()->setCellValue('A14', 'Count:');
  46. $objPHPExcel->getActiveSheet()->setCellValue('B1', 'Range 1');
  47. $objPHPExcel->getActiveSheet()->setCellValue('B2', 2);
  48. $objPHPExcel->getActiveSheet()->setCellValue('B3', 8);
  49. $objPHPExcel->getActiveSheet()->setCellValue('B4', 10);
  50. $objPHPExcel->getActiveSheet()->setCellValue('B5', True);
  51. $objPHPExcel->getActiveSheet()->setCellValue('B6', False);
  52. $objPHPExcel->getActiveSheet()->setCellValue('B7', 'Text String');
  53. $objPHPExcel->getActiveSheet()->setCellValue('B9', '22');
  54. $objPHPExcel->getActiveSheet()->setCellValue('B10', 4);
  55. $objPHPExcel->getActiveSheet()->setCellValue('B11', 6);
  56. $objPHPExcel->getActiveSheet()->setCellValue('B12', 12);
  57. $objPHPExcel->getActiveSheet()->setCellValue('B14', '=COUNT(B2:B12)');
  58. $objPHPExcel->getActiveSheet()->setCellValue('C1', 'Range 2');
  59. $objPHPExcel->getActiveSheet()->setCellValue('C2', 1);
  60. $objPHPExcel->getActiveSheet()->setCellValue('C3', 2);
  61. $objPHPExcel->getActiveSheet()->setCellValue('C4', 2);
  62. $objPHPExcel->getActiveSheet()->setCellValue('C5', 3);
  63. $objPHPExcel->getActiveSheet()->setCellValue('C6', 3);
  64. $objPHPExcel->getActiveSheet()->setCellValue('C7', 3);
  65. $objPHPExcel->getActiveSheet()->setCellValue('C8', '0');
  66. $objPHPExcel->getActiveSheet()->setCellValue('C9', 4);
  67. $objPHPExcel->getActiveSheet()->setCellValue('C10', 4);
  68. $objPHPExcel->getActiveSheet()->setCellValue('C11', 4);
  69. $objPHPExcel->getActiveSheet()->setCellValue('C12', 4);
  70. $objPHPExcel->getActiveSheet()->setCellValue('C14', '=COUNT(C2:C12)');
  71. $objPHPExcel->getActiveSheet()->setCellValue('D1', 'Range 3');
  72. $objPHPExcel->getActiveSheet()->setCellValue('D2', 2);
  73. $objPHPExcel->getActiveSheet()->setCellValue('D3', 3);
  74. $objPHPExcel->getActiveSheet()->setCellValue('D4', 4);
  75. $objPHPExcel->getActiveSheet()->setCellValue('D5', '=((D2 * D3) + D4) & " should be 10"');
  76. $objPHPExcel->getActiveSheet()->setCellValue('E1', 'Other functions');
  77. $objPHPExcel->getActiveSheet()->setCellValue('E2', '=PI()');
  78. $objPHPExcel->getActiveSheet()->setCellValue('E3', '=RAND()');
  79. $objPHPExcel->getActiveSheet()->setCellValue('E4', '=RANDBETWEEN(5, 10)');
  80. $objPHPExcel->getActiveSheet()->setCellValue('E14', 'Count of both ranges:');
  81. $objPHPExcel->getActiveSheet()->setCellValue('F14', '=COUNT(B2:C12)');
  82. // Calculated data
  83. echo date('H:i:s') . " Calculated data\n";
  84. echo 'Value of B14 [=COUNT(B2:B12)]: ' . $objPHPExcel->getActiveSheet()->getCell('B14')->getCalculatedValue() . "\r\n";
  85. // Echo memory peak usage
  86. echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";
  87. // Echo done
  88. echo date('H:i:s') . " Done" , EOL;