PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.11
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.11
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / phpoffice / phpspreadsheet / samples / Calculations / Database / DVAR.php

DVAR.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.4.11, at vendor/phpoffice/phpspreadsheet/samples/Calculations/Database/DVAR.php

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