For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.6 KiB

  1. <?php
  2. error_reporting(E_ALL);
  3. set_time_limit(0);
  4. date_default_timezone_set('Europe/London');
  5. ?>
  6. <html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  9. <title>PHPExcel Calculation Examples</title>
  10. </head>
  11. <body>
  12. <h1>DSTDEV</h1>
  13. <h2>Estimates the standard deviation based on a sample of selected database entries.</h2>
  14. <?php
  15. /** Include path **/
  16. set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
  17. /** Include PHPExcel */
  18. include 'PHPExcel.php';
  19. // Create new PHPExcel object
  20. $objPHPExcel = new PHPExcel();
  21. $worksheet = $objPHPExcel->getActiveSheet();
  22. // Add some data
  23. $database = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit' ),
  24. array( 'Apple', 18, 20, 14, 105.00 ),
  25. array( 'Pear', 12, 12, 10, 96.00 ),
  26. array( 'Cherry', 13, 14, 9, 105.00 ),
  27. array( 'Apple', 14, 15, 10, 75.00 ),
  28. array( 'Pear', 9, 8, 8, 76.80 ),
  29. array( 'Apple', 8, 9, 6, 45.00 ),
  30. );
  31. $criteria = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height' ),
  32. array( '="=Apple"', '>10', NULL, NULL, NULL, '<16' ),
  33. array( '="=Pear"', NULL, NULL, NULL, NULL, NULL )
  34. );
  35. $worksheet->fromArray( $criteria, NULL, 'A1' );
  36. $worksheet->fromArray( $database, NULL, 'A4' );
  37. $worksheet->setCellValue('A12', 'The estimated standard deviation in the yield of Apple and Pear trees');
  38. $worksheet->setCellValue('B12', '=DSTDEV(A4:E10,"Yield",A1:A3)');
  39. $worksheet->setCellValue('A13', 'The estimated standard deviation in height of Apple and Pear trees');
  40. $worksheet->setCellValue('B13', '=DSTDEV(A4:E10,2,A1:A3)');
  41. echo '<hr />';
  42. echo '<h4>Database</h4>';
  43. $databaseData = $worksheet->rangeToArray('A4:E10',null,true,true,true);
  44. var_dump($databaseData);
  45. echo '<hr />';
  46. // Test the formulae
  47. echo '<h4>Criteria</h4>';
  48. $criteriaData = $worksheet->rangeToArray('A1:A3',null,true,true,true);
  49. var_dump($criteriaData);
  50. echo $worksheet->getCell("A12")->getValue() .'<br />';
  51. echo 'DSTDEV() Result is ' . $worksheet->getCell("B12")->getCalculatedValue() .'<br /><br />';
  52. echo '<h4>Criteria</h4>';
  53. $criteriaData = $worksheet->rangeToArray('A1:A3',null,true,true,true);
  54. var_dump($criteriaData);
  55. echo $worksheet->getCell("A13")->getValue() .'<br />';
  56. echo 'DSTDEV() Result is ' . $worksheet->getCell("B13")->getCalculatedValue();
  57. ?>
  58. <body>
  59. </html>