| 1 |
<?php |
| 2 |
|
| 3 |
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
| 4 |
|
| 5 |
require __DIR__ . '/../../Header.php'; |
| 6 |
|
| 7 |
$helper->log('Estimates the standard deviation based on a sample of selected database entries.'); |
| 8 |
|
| 9 |
// Create new PhpSpreadsheet object |
| 10 |
$spreadsheet = new Spreadsheet(); |
| 11 |
$worksheet = $spreadsheet->getActiveSheet(); |
| 12 |
|
| 13 |
// Add some data |
| 14 |
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'], |
| 15 |
['Apple', 18, 20, 14, 105.00], |
| 16 |
['Pear', 12, 12, 10, 96.00], |
| 17 |
['Cherry', 13, 14, 9, 105.00], |
| 18 |
['Apple', 14, 15, 10, 75.00], |
| 19 |
['Pear', 9, 8, 8, 76.80], |
| 20 |
['Apple', 8, 9, 6, 45.00], |
| 21 |
]; |
| 22 |
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'], |
| 23 |
['="=Apple"', '>10', null, null, null, '<16'], |
| 24 |
['="=Pear"', null, null, null, null, null], |
| 25 |
]; |
| 26 |
|
| 27 |
$worksheet->fromArray($criteria, null, 'A1'); |
| 28 |
$worksheet->fromArray($database, null, 'A4'); |
| 29 |
|
| 30 |
$worksheet->setCellValue('A12', 'The estimated standard deviation in the yield of Apple and Pear trees'); |
| 31 |
$worksheet->setCellValue('B12', '=DSTDEV(A4:E10,"Yield",A1:A3)'); |
| 32 |
|
| 33 |
$worksheet->setCellValue('A13', 'The estimated standard deviation in height of Apple and Pear trees'); |
| 34 |
$worksheet->setCellValue('B13', '=DSTDEV(A4:E10,2,A1:A3)'); |
| 35 |
|
| 36 |
$helper->log('Database'); |
| 37 |
|
| 38 |
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true); |
| 39 |
var_dump($databaseData); |
| 40 |
|
| 41 |
// Test the formulae |
| 42 |
$helper->log('Criteria'); |
| 43 |
|
| 44 |
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); |
| 45 |
var_dump($criteriaData); |
| 46 |
|
| 47 |
$helper->log($worksheet->getCell('A12')->getValue()); |
| 48 |
$helper->log('DSTDEV() Result is ' . $worksheet->getCell('B12')->getCalculatedValue()); |
| 49 |
|
| 50 |
$helper->log('Criteria'); |
| 51 |
|
| 52 |
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true); |
| 53 |
var_dump($criteriaData); |
| 54 |
|
| 55 |
$helper->log($worksheet->getCell('A13')->getValue()); |
| 56 |
$helper->log('DSTDEV() Result is ' . $worksheet->getCell('B13')->getCalculatedValue()); |
| 57 |
|