1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace PhpOffice\PhpSpreadsheet\Calculation\Database;
|
|
|
4 |
|
|
|
5 |
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
|
|
6 |
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Counts;
|
|
|
7 |
|
|
|
8 |
class DCount extends DatabaseAbstract
|
|
|
9 |
{
|
|
|
10 |
/**
|
|
|
11 |
* DCOUNT.
|
|
|
12 |
*
|
|
|
13 |
* Counts the cells that contain numbers in a column of a list or database that match conditions
|
|
|
14 |
* that you specify.
|
|
|
15 |
*
|
|
|
16 |
* Excel Function:
|
|
|
17 |
* DCOUNT(database,[field],criteria)
|
|
|
18 |
*
|
|
|
19 |
* @param mixed[] $database The range of cells that makes up the list or database.
|
|
|
20 |
* A database is a list of related data in which rows of related
|
|
|
21 |
* information are records, and columns of data are fields. The
|
|
|
22 |
* first row of the list contains labels for each column.
|
|
|
23 |
* @param null|array|int|string $field Indicates which column is used in the function. Enter the
|
|
|
24 |
* column label enclosed between double quotation marks, such as
|
|
|
25 |
* "Age" or "Yield," or a number (without quotation marks) that
|
|
|
26 |
* represents the position of the column within the list: 1 for
|
|
|
27 |
* the first column, 2 for the second column, and so on.
|
|
|
28 |
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
|
|
29 |
* You can use any range for the criteria argument, as long as it
|
|
|
30 |
* includes at least one column label and at least one cell below
|
|
|
31 |
* the column label in which you specify a condition for the
|
|
|
32 |
* column.
|
|
|
33 |
*/
|
|
|
34 |
public static function evaluate(array $database, array|null|int|string $field, array $criteria, bool $returnError = true): string|int
|
|
|
35 |
{
|
|
|
36 |
$field = self::fieldExtract($database, $field);
|
|
|
37 |
if ($returnError && $field === null) {
|
|
|
38 |
return ExcelError::VALUE();
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
return Counts::COUNT(
|
|
|
42 |
self::getFilteredColumn($database, $field, $criteria)
|
|
|
43 |
);
|
|
|
44 |
}
|
|
|
45 |
}
|