|
3 | 3 | use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
4 | 4 |
|
5 | 5 | require __DIR__ . '/../../Header.php';
|
6 |
| -$helper->log('Counts the cells that contain numbers in a database.'); |
| 6 | + |
| 7 | +$category = 'Database'; |
| 8 | +$functionName = 'DCOUNT'; |
| 9 | +$description = 'Counts the cells that contain numbers in a set of database records that match criteria'; |
| 10 | + |
| 11 | +$helper->titles($category, $functionName, $description); |
7 | 12 |
|
8 | 13 | // Create new PhpSpreadsheet object
|
9 | 14 | $spreadsheet = new Spreadsheet();
|
|
14 | 19 | ['Apple', 18, 20, 14, 105.00],
|
15 | 20 | ['Pear', 12, 12, 10, 96.00],
|
16 | 21 | ['Cherry', 13, 14, 9, 105.00],
|
17 |
| - ['Apple', 14, 15, 10, 75.00], |
18 |
| - ['Pear', 9, 8, 8, 76.80], |
19 |
| - ['Apple', 8, 9, 6, 45.00], |
| 22 | + ['Apple', 14, 'N/A', 10, 75.00], |
| 23 | + ['Pear', 9, 8, 8, 77.00], |
| 24 | + ['Apple', 12, 11, 6, 45.00], |
20 | 25 | ];
|
21 | 26 | $criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
22 | 27 | ['="=Apple"', '>10', null, null, null, '<16'],
|
|
26 | 31 | $worksheet->fromArray($criteria, null, 'A1');
|
27 | 32 | $worksheet->fromArray($database, null, 'A4');
|
28 | 33 |
|
29 |
| -$worksheet->setCellValue('A12', 'The Number of Apple trees over 10\' in height'); |
30 |
| -$worksheet->setCellValue('B12', '=DCOUNT(A4:E10,"Yield",A1:B2)'); |
| 34 | +$worksheet->setCellValue('A12', 'The Number of Apple trees between 10\' and 16\' in height whose age is known'); |
| 35 | +$worksheet->setCellValue('B12', '=DCOUNT(A4:E10,"Age",A1:F2)'); |
31 | 36 |
|
32 |
| -$worksheet->setCellValue('A13', 'The Number of Apple and Pear trees in the orchard'); |
| 37 | +$worksheet->setCellValue('A13', 'The Number of Apple and Pear trees in the orchard with a numeric value in column 3 ("Age")'); |
33 | 38 | $worksheet->setCellValue('B13', '=DCOUNT(A4:E10,3,A1:A3)');
|
34 | 39 |
|
35 | 40 | $helper->log('Database');
|
36 | 41 |
|
37 | 42 | $databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
|
38 |
| -var_dump($databaseData); |
| 43 | +$helper->displayGrid($databaseData); |
39 | 44 |
|
40 | 45 | // Test the formulae
|
41 | 46 | $helper->log('Criteria');
|
42 | 47 |
|
43 |
| -$criteriaData = $worksheet->rangeToArray('A1:B2', null, true, true, true); |
44 |
| -var_dump($criteriaData); |
| 48 | +$criteriaData = $worksheet->rangeToArray('A1:F2', null, true, true, true); |
| 49 | +$helper->displayGrid($criteriaData); |
45 | 50 |
|
46 |
| -$helper->log($worksheet->getCell('A12')->getValue()); |
47 |
| -$helper->log('DCOUNT() Result is ' . $worksheet->getCell('B12')->getCalculatedValue()); |
| 51 | +$helper->logCalculationResult($worksheet, $functionName, 'B12', 'A12'); |
48 | 52 |
|
49 | 53 | $helper->log('Criteria');
|
50 | 54 |
|
51 | 55 | $criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
52 |
| -var_dump($criteriaData); |
| 56 | +$helper->displayGrid($criteriaData); |
53 | 57 |
|
54 |
| -$helper->log($worksheet->getCell('A13')->getValue()); |
55 |
| -$helper->log('DCOUNT() Result is ' . $worksheet->getCell('B13')->getCalculatedValue()); |
| 58 | +$helper->logCalculationResult($worksheet, $functionName, 'B13', 'A13'); |
0 commit comments