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.

86 lines
2.4 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>DPRODUCT</h1>
  13. <h2>Multiplies the values in a column of a list or database that match conditions that you specify.</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 product of the yields of all Apple trees over 10\' in the orchard');
  38. $worksheet->setCellValue('B12', '=DPRODUCT(A4:E10,"Yield",A1:B2)');
  39. echo '<hr />';
  40. echo '<h4>Database</h4>';
  41. $databaseData = $worksheet->rangeToArray('A4:E10',null,true,true,true);
  42. var_dump($databaseData);
  43. echo '<hr />';
  44. // Test the formulae
  45. echo '<h4>Criteria</h4>';
  46. echo 'ALL' . '<br /><br />';
  47. echo $worksheet->getCell("A12")->getValue() .'<br />';
  48. echo 'DMAX() Result is ' . $worksheet->getCell("B12")->getCalculatedValue() .'<br /><br />';
  49. echo '<h4>Criteria</h4>';
  50. $criteriaData = $worksheet->rangeToArray('A1:A2',null,true,true,true);
  51. var_dump($criteriaData);
  52. echo $worksheet->getCell("A13")->getValue() .'<br />';
  53. echo 'DMAX() Result is ' . $worksheet->getCell("B13")->getCalculatedValue();
  54. ?>
  55. <body>
  56. </html>