← All changes
|
vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Database.php
+661
-612
3.1.1
→
3.0.10
View file →
| @@ -1,19 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -/** PHPExcel root directory */ | |
| 4 | -if (!defined('PHPEXCEL_ROOT')) { | |
| 5 | - /** | |
| 6 | - * @ignore | |
| 7 | - */ | |
| 8 | - define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); | |
| 9 | - require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); | |
| 10 | -} | |
| 11 | - | |
| 12 | 2 | /** |
| 13 | - * PHPExcel_Calculation_Database | |
| 3 | + * PHPExcel | |
| 14 | 4 | * |
| 15 | - * Copyright (c) 2006 - 2015 PHPExcel | |
| 5 | + * Copyright (c) 2006 - 2014 PHPExcel | |
| 16 | 6 | * |
| 17 | 7 | * This library is free software; you can redistribute it and/or |
| 18 | 8 | * modify it under the terms of the GNU Lesser General Public |
| 19 | 9 | * License as published by the Free Software Foundation; either |
| @@ -27,650 +17,709 @@ | ||
| 27 | 17 | * You should have received a copy of the GNU Lesser General Public |
| 28 | 18 | * License along with this library; if not, write to the Free Software |
| 29 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 30 | 20 | * |
| 31 | - * @category PHPExcel | |
| 32 | - * @package PHPExcel_Calculation | |
| 33 | - * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 34 | - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL | |
| 35 | - * @version ##VERSION##, ##DATE## | |
| 21 | + * @category PHPExcel | |
| 22 | + * @package PHPExcel_Calculation | |
| 23 | + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 24 | + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL | |
| 25 | + * @version ##VERSION##, ##DATE## | |
| 36 | 26 | */ |
| 37 | -class PHPExcel_Calculation_Database | |
| 38 | -{ | |
| 39 | - /** | |
| 40 | - * fieldExtract | |
| 41 | - * | |
| 42 | - * Extracts the column ID to use for the data field. | |
| 43 | - * | |
| 44 | - * @access private | |
| 45 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 46 | - * A database is a list of related data in which rows of related | |
| 47 | - * information are records, and columns of data are fields. The | |
| 48 | - * first row of the list contains labels for each column. | |
| 49 | - * @param mixed $field Indicates which column is used in the function. Enter the | |
| 50 | - * column label enclosed between double quotation marks, such as | |
| 51 | - * "Age" or "Yield," or a number (without quotation marks) that | |
| 52 | - * represents the position of the column within the list: 1 for | |
| 53 | - * the first column, 2 for the second column, and so on. | |
| 54 | - * @return string|NULL | |
| 55 | - * | |
| 56 | - */ | |
| 57 | - private static function fieldExtract($database, $field) | |
| 58 | - { | |
| 59 | - $field = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($field)); | |
| 60 | - $fieldNames = array_map('strtoupper', array_shift($database)); | |
| 61 | 27 | |
| 62 | - if (is_numeric($field)) { | |
| 63 | - $keys = array_keys($fieldNames); | |
| 64 | - return $keys[$field-1]; | |
| 65 | - } | |
| 66 | - $key = array_search($field, $fieldNames); | |
| 67 | - return ($key) ? $key : null; | |
| 68 | - } | |
| 69 | 28 | |
| 70 | - /** | |
| 71 | - * filter | |
| 72 | - * | |
| 73 | - * Parses the selection criteria, extracts the database rows that match those criteria, and | |
| 74 | - * returns that subset of rows. | |
| 75 | - * | |
| 76 | - * @access private | |
| 77 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 78 | - * A database is a list of related data in which rows of related | |
| 79 | - * information are records, and columns of data are fields. The | |
| 80 | - * first row of the list contains labels for each column. | |
| 81 | - * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 82 | - * You can use any range for the criteria argument, as long as it | |
| 83 | - * includes at least one column label and at least one cell below | |
| 84 | - * the column label in which you specify a condition for the | |
| 85 | - * column. | |
| 86 | - * @return array of mixed | |
| 87 | - * | |
| 88 | - */ | |
| 89 | - private static function filter($database, $criteria) | |
| 90 | - { | |
| 91 | - $fieldNames = array_shift($database); | |
| 92 | - $criteriaNames = array_shift($criteria); | |
| 29 | +/** PHPExcel root directory */ | |
| 30 | +if (!defined('PHPEXCEL_ROOT')) { | |
| 31 | + /** | |
| 32 | + * @ignore | |
| 33 | + */ | |
| 34 | + define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); | |
| 35 | + require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); | |
| 36 | +} | |
| 93 | 37 | |
| 94 | - // Convert the criteria into a set of AND/OR conditions with [:placeholders] | |
| 95 | - $testConditions = $testValues = array(); | |
| 96 | - $testConditionsCount = 0; | |
| 97 | - foreach ($criteriaNames as $key => $criteriaName) { | |
| 98 | - $testCondition = array(); | |
| 99 | - $testConditionCount = 0; | |
| 100 | - foreach ($criteria as $row => $criterion) { | |
| 101 | - if ($criterion[$key] > '') { | |
| 102 | - $testCondition[] = '[:'.$criteriaName.']'.PHPExcel_Calculation_Functions::ifCondition($criterion[$key]); | |
| 103 | - $testConditionCount++; | |
| 104 | - } | |
| 105 | - } | |
| 106 | - if ($testConditionCount > 1) { | |
| 107 | - $testConditions[] = 'OR(' . implode(',', $testCondition) . ')'; | |
| 108 | - $testConditionsCount++; | |
| 109 | - } elseif ($testConditionCount == 1) { | |
| 110 | - $testConditions[] = $testCondition[0]; | |
| 111 | - $testConditionsCount++; | |
| 112 | - } | |
| 113 | - } | |
| 114 | 38 | |
| 115 | - if ($testConditionsCount > 1) { | |
| 116 | - $testConditionSet = 'AND(' . implode(',', $testConditions) . ')'; | |
| 117 | - } elseif ($testConditionsCount == 1) { | |
| 118 | - $testConditionSet = $testConditions[0]; | |
| 119 | - } | |
| 39 | +/** | |
| 40 | + * PHPExcel_Calculation_Database | |
| 41 | + * | |
| 42 | + * @category PHPExcel | |
| 43 | + * @package PHPExcel_Calculation | |
| 44 | + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 45 | + */ | |
| 46 | +class PHPExcel_Calculation_Database { | |
| 120 | 47 | |
| 121 | - // Loop through each row of the database | |
| 122 | - foreach ($database as $dataRow => $dataValues) { | |
| 123 | - // Substitute actual values from the database row for our [:placeholders] | |
| 124 | - $testConditionList = $testConditionSet; | |
| 125 | - foreach ($criteriaNames as $key => $criteriaName) { | |
| 126 | - $k = array_search($criteriaName, $fieldNames); | |
| 127 | - if (isset($dataValues[$k])) { | |
| 128 | - $dataValue = $dataValues[$k]; | |
| 129 | - $dataValue = (is_string($dataValue)) ? PHPExcel_Calculation::wrapResult(strtoupper($dataValue)) : $dataValue; | |
| 130 | - $testConditionList = str_replace('[:' . $criteriaName . ']', $dataValue, $testConditionList); | |
| 131 | - } | |
| 132 | - } | |
| 133 | - // evaluate the criteria against the row data | |
| 134 | - $result = PHPExcel_Calculation::getInstance()->_calculateFormulaValue('='.$testConditionList); | |
| 135 | - // If the row failed to meet the criteria, remove it from the database | |
| 136 | - if (!$result) { | |
| 137 | - unset($database[$dataRow]); | |
| 138 | - } | |
| 139 | - } | |
| 140 | 48 | |
| 141 | - return $database; | |
| 142 | - } | |
| 49 | + /** | |
| 50 | + * __fieldExtract | |
| 51 | + * | |
| 52 | + * Extracts the column ID to use for the data field. | |
| 53 | + * | |
| 54 | + * @access private | |
| 55 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 56 | + * A database is a list of related data in which rows of related | |
| 57 | + * information are records, and columns of data are fields. The | |
| 58 | + * first row of the list contains labels for each column. | |
| 59 | + * @param mixed $field Indicates which column is used in the function. Enter the | |
| 60 | + * column label enclosed between double quotation marks, such as | |
| 61 | + * "Age" or "Yield," or a number (without quotation marks) that | |
| 62 | + * represents the position of the column within the list: 1 for | |
| 63 | + * the first column, 2 for the second column, and so on. | |
| 64 | + * @return string|NULL | |
| 65 | + * | |
| 66 | + */ | |
| 67 | + private static function __fieldExtract($database,$field) { | |
| 68 | + $field = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($field)); | |
| 69 | + $fieldNames = array_map('strtoupper',array_shift($database)); | |
| 143 | 70 | |
| 71 | + if (is_numeric($field)) { | |
| 72 | + $keys = array_keys($fieldNames); | |
| 73 | + return $keys[$field-1]; | |
| 74 | + } | |
| 75 | + $key = array_search($field,$fieldNames); | |
| 76 | + return ($key) ? $key : NULL; | |
| 77 | + } | |
| 144 | 78 | |
| 145 | - private static function getFilteredColumn($database, $field, $criteria) | |
| 146 | - { | |
| 147 | - // reduce the database to a set of rows that match all the criteria | |
| 148 | - $database = self::filter($database, $criteria); | |
| 149 | - // extract an array of values for the requested column | |
| 150 | - $colData = array(); | |
| 151 | - foreach ($database as $row) { | |
| 152 | - $colData[] = $row[$field]; | |
| 153 | - } | |
| 154 | - | |
| 155 | - return $colData; | |
| 156 | - } | |
| 79 | + /** | |
| 80 | + * __filter | |
| 81 | + * | |
| 82 | + * Parses the selection criteria, extracts the database rows that match those criteria, and | |
| 83 | + * returns that subset of rows. | |
| 84 | + * | |
| 85 | + * @access private | |
| 86 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 87 | + * A database is a list of related data in which rows of related | |
| 88 | + * information are records, and columns of data are fields. The | |
| 89 | + * first row of the list contains labels for each column. | |
| 90 | + * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 91 | + * You can use any range for the criteria argument, as long as it | |
| 92 | + * includes at least one column label and at least one cell below | |
| 93 | + * the column label in which you specify a condition for the | |
| 94 | + * column. | |
| 95 | + * @return array of mixed | |
| 96 | + * | |
| 97 | + */ | |
| 98 | + private static function __filter($database,$criteria) { | |
| 99 | + $fieldNames = array_shift($database); | |
| 100 | + $criteriaNames = array_shift($criteria); | |
| 157 | 101 | |
| 158 | - /** | |
| 159 | - * DAVERAGE | |
| 160 | - * | |
| 161 | - * Averages the values in a column of a list or database that match conditions you specify. | |
| 162 | - * | |
| 163 | - * Excel Function: | |
| 164 | - * DAVERAGE(database,field,criteria) | |
| 165 | - * | |
| 166 | - * @access public | |
| 167 | - * @category Database Functions | |
| 168 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 169 | - * A database is a list of related data in which rows of related | |
| 170 | - * information are records, and columns of data are fields. The | |
| 171 | - * first row of the list contains labels for each column. | |
| 172 | - * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 173 | - * column label enclosed between double quotation marks, such as | |
| 174 | - * "Age" or "Yield," or a number (without quotation marks) that | |
| 175 | - * represents the position of the column within the list: 1 for | |
| 176 | - * the first column, 2 for the second column, and so on. | |
| 177 | - * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 178 | - * You can use any range for the criteria argument, as long as it | |
| 179 | - * includes at least one column label and at least one cell below | |
| 180 | - * the column label in which you specify a condition for the | |
| 181 | - * column. | |
| 182 | - * @return float | |
| 183 | - * | |
| 184 | - */ | |
| 185 | - public static function DAVERAGE($database, $field, $criteria) | |
| 186 | - { | |
| 187 | - $field = self::fieldExtract($database, $field); | |
| 188 | - if (is_null($field)) { | |
| 189 | - return null; | |
| 190 | - } | |
| 102 | + // Convert the criteria into a set of AND/OR conditions with [:placeholders] | |
| 103 | + $testConditions = $testValues = array(); | |
| 104 | + $testConditionsCount = 0; | |
| 105 | + foreach($criteriaNames as $key => $criteriaName) { | |
| 106 | + $testCondition = array(); | |
| 107 | + $testConditionCount = 0; | |
| 108 | + foreach($criteria as $row => $criterion) { | |
| 109 | + if ($criterion[$key] > '') { | |
| 110 | + $testCondition[] = '[:'.$criteriaName.']'.PHPExcel_Calculation_Functions::_ifCondition($criterion[$key]); | |
| 111 | + $testConditionCount++; | |
| 112 | + } | |
| 113 | + } | |
| 114 | + if ($testConditionCount > 1) { | |
| 115 | + $testConditions[] = 'OR('.implode(',',$testCondition).')'; | |
| 116 | + $testConditionsCount++; | |
| 117 | + } elseif($testConditionCount == 1) { | |
| 118 | + $testConditions[] = $testCondition[0]; | |
| 119 | + $testConditionsCount++; | |
| 120 | + } | |
| 121 | + } | |
| 191 | 122 | |
| 192 | - // Return | |
| 193 | - return PHPExcel_Calculation_Statistical::AVERAGE( | |
| 194 | - self::getFilteredColumn($database, $field, $criteria) | |
| 195 | - ); | |
| 196 | - } | |
| 123 | + if ($testConditionsCount > 1) { | |
| 124 | + $testConditionSet = 'AND('.implode(',',$testConditions).')'; | |
| 125 | + } elseif($testConditionsCount == 1) { | |
| 126 | + $testConditionSet = $testConditions[0]; | |
| 127 | + } | |
| 197 | 128 | |
| 129 | + // Loop through each row of the database | |
| 130 | + foreach($database as $dataRow => $dataValues) { | |
| 131 | + // Substitute actual values from the database row for our [:placeholders] | |
| 132 | + $testConditionList = $testConditionSet; | |
| 133 | + foreach($criteriaNames as $key => $criteriaName) { | |
| 134 | + $k = array_search($criteriaName,$fieldNames); | |
| 135 | + if (isset($dataValues[$k])) { | |
| 136 | + $dataValue = $dataValues[$k]; | |
| 137 | + $dataValue = (is_string($dataValue)) ? PHPExcel_Calculation::_wrapResult(strtoupper($dataValue)) : $dataValue; | |
| 138 | + $testConditionList = str_replace('[:'.$criteriaName.']',$dataValue,$testConditionList); | |
| 139 | + } | |
| 140 | + } | |
| 141 | + // evaluate the criteria against the row data | |
| 142 | + $result = PHPExcel_Calculation::getInstance()->_calculateFormulaValue('='.$testConditionList); | |
| 143 | + // If the row failed to meet the criteria, remove it from the database | |
| 144 | + if (!$result) { | |
| 145 | + unset($database[$dataRow]); | |
| 146 | + } | |
| 147 | + } | |
| 198 | 148 | |
| 199 | - /** | |
| 200 | - * DCOUNT | |
| 201 | - * | |
| 202 | - * Counts the cells that contain numbers in a column of a list or database that match conditions | |
| 203 | - * that you specify. | |
| 204 | - * | |
| 205 | - * Excel Function: | |
| 206 | - * DCOUNT(database,[field],criteria) | |
| 207 | - * | |
| 208 | - * Excel Function: | |
| 209 | - * DAVERAGE(database,field,criteria) | |
| 210 | - * | |
| 211 | - * @access public | |
| 212 | - * @category Database Functions | |
| 213 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 214 | - * A database is a list of related data in which rows of related | |
| 215 | - * information are records, and columns of data are fields. The | |
| 216 | - * first row of the list contains labels for each column. | |
| 217 | - * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 218 | - * column label enclosed between double quotation marks, such as | |
| 219 | - * "Age" or "Yield," or a number (without quotation marks) that | |
| 220 | - * represents the position of the column within the list: 1 for | |
| 221 | - * the first column, 2 for the second column, and so on. | |
| 222 | - * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 223 | - * You can use any range for the criteria argument, as long as it | |
| 224 | - * includes at least one column label and at least one cell below | |
| 225 | - * the column label in which you specify a condition for the | |
| 226 | - * column. | |
| 227 | - * @return integer | |
| 228 | - * | |
| 229 | - * @TODO The field argument is optional. If field is omitted, DCOUNT counts all records in the | |
| 230 | - * database that match the criteria. | |
| 231 | - * | |
| 232 | - */ | |
| 233 | - public static function DCOUNT($database, $field, $criteria) | |
| 234 | - { | |
| 235 | - $field = self::fieldExtract($database, $field); | |
| 236 | - if (is_null($field)) { | |
| 237 | - return null; | |
| 238 | - } | |
| 149 | + return $database; | |
| 150 | + } | |
| 239 | 151 | |
| 240 | - // Return | |
| 241 | - return PHPExcel_Calculation_Statistical::COUNT( | |
| 242 | - self::getFilteredColumn($database, $field, $criteria) | |
| 243 | - ); | |
| 244 | - } | |
| 245 | 152 | |
| 153 | + /** | |
| 154 | + * DAVERAGE | |
| 155 | + * | |
| 156 | + * Averages the values in a column of a list or database that match conditions you specify. | |
| 157 | + * | |
| 158 | + * Excel Function: | |
| 159 | + * DAVERAGE(database,field,criteria) | |
| 160 | + * | |
| 161 | + * @access public | |
| 162 | + * @category Database Functions | |
| 163 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 164 | + * A database is a list of related data in which rows of related | |
| 165 | + * information are records, and columns of data are fields. The | |
| 166 | + * first row of the list contains labels for each column. | |
| 167 | + * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 168 | + * column label enclosed between double quotation marks, such as | |
| 169 | + * "Age" or "Yield," or a number (without quotation marks) that | |
| 170 | + * represents the position of the column within the list: 1 for | |
| 171 | + * the first column, 2 for the second column, and so on. | |
| 172 | + * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 173 | + * You can use any range for the criteria argument, as long as it | |
| 174 | + * includes at least one column label and at least one cell below | |
| 175 | + * the column label in which you specify a condition for the | |
| 176 | + * column. | |
| 177 | + * @return float | |
| 178 | + * | |
| 179 | + */ | |
| 180 | + public static function DAVERAGE($database,$field,$criteria) { | |
| 181 | + $field = self::__fieldExtract($database,$field); | |
| 182 | + if (is_null($field)) { | |
| 183 | + return NULL; | |
| 184 | + } | |
| 185 | + // reduce the database to a set of rows that match all the criteria | |
| 186 | + $database = self::__filter($database,$criteria); | |
| 187 | + // extract an array of values for the requested column | |
| 188 | + $colData = array(); | |
| 189 | + foreach($database as $row) { | |
| 190 | + $colData[] = $row[$field]; | |
| 191 | + } | |
| 246 | 192 | |
| 247 | - /** | |
| 248 | - * DCOUNTA | |
| 249 | - * | |
| 250 | - * Counts the nonblank cells in a column of a list or database that match conditions that you specify. | |
| 251 | - * | |
| 252 | - * Excel Function: | |
| 253 | - * DCOUNTA(database,[field],criteria) | |
| 254 | - * | |
| 255 | - * @access public | |
| 256 | - * @category Database Functions | |
| 257 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 258 | - * A database is a list of related data in which rows of related | |
| 259 | - * information are records, and columns of data are fields. The | |
| 260 | - * first row of the list contains labels for each column. | |
| 261 | - * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 262 | - * column label enclosed between double quotation marks, such as | |
| 263 | - * "Age" or "Yield," or a number (without quotation marks) that | |
| 264 | - * represents the position of the column within the list: 1 for | |
| 265 | - * the first column, 2 for the second column, and so on. | |
| 266 | - * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 267 | - * You can use any range for the criteria argument, as long as it | |
| 268 | - * includes at least one column label and at least one cell below | |
| 269 | - * the column label in which you specify a condition for the | |
| 270 | - * column. | |
| 271 | - * @return integer | |
| 272 | - * | |
| 273 | - * @TODO The field argument is optional. If field is omitted, DCOUNTA counts all records in the | |
| 274 | - * database that match the criteria. | |
| 275 | - * | |
| 276 | - */ | |
| 277 | - public static function DCOUNTA($database, $field, $criteria) | |
| 278 | - { | |
| 279 | - $field = self::fieldExtract($database, $field); | |
| 280 | - if (is_null($field)) { | |
| 281 | - return null; | |
| 282 | - } | |
| 193 | + // Return | |
| 194 | + return PHPExcel_Calculation_Statistical::AVERAGE($colData); | |
| 195 | + } // function DAVERAGE() | |
| 283 | 196 | |
| 284 | - // reduce the database to a set of rows that match all the criteria | |
| 285 | - $database = self::filter($database, $criteria); | |
| 286 | - // extract an array of values for the requested column | |
| 287 | - $colData = array(); | |
| 288 | - foreach ($database as $row) { | |
| 289 | - $colData[] = $row[$field]; | |
| 290 | - } | |
| 291 | 197 | |
| 292 | - // Return | |
| 293 | - return PHPExcel_Calculation_Statistical::COUNTA( | |
| 294 | - self::getFilteredColumn($database, $field, $criteria) | |
| 295 | - ); | |
| 296 | - } | |
| 198 | + /** | |
| 199 | + * DCOUNT | |
| 200 | + * | |
| 201 | + * Counts the cells that contain numbers in a column of a list or database that match conditions | |
| 202 | + * that you specify. | |
| 203 | + * | |
| 204 | + * Excel Function: | |
| 205 | + * DCOUNT(database,[field],criteria) | |
| 206 | + * | |
| 207 | + * Excel Function: | |
| 208 | + * DAVERAGE(database,field,criteria) | |
| 209 | + * | |
| 210 | + * @access public | |
| 211 | + * @category Database Functions | |
| 212 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 213 | + * A database is a list of related data in which rows of related | |
| 214 | + * information are records, and columns of data are fields. The | |
| 215 | + * first row of the list contains labels for each column. | |
| 216 | + * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 217 | + * column label enclosed between double quotation marks, such as | |
| 218 | + * "Age" or "Yield," or a number (without quotation marks) that | |
| 219 | + * represents the position of the column within the list: 1 for | |
| 220 | + * the first column, 2 for the second column, and so on. | |
| 221 | + * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 222 | + * You can use any range for the criteria argument, as long as it | |
| 223 | + * includes at least one column label and at least one cell below | |
| 224 | + * the column label in which you specify a condition for the | |
| 225 | + * column. | |
| 226 | + * @return integer | |
| 227 | + * | |
| 228 | + * @TODO The field argument is optional. If field is omitted, DCOUNT counts all records in the | |
| 229 | + * database that match the criteria. | |
| 230 | + * | |
| 231 | + */ | |
| 232 | + public static function DCOUNT($database,$field,$criteria) { | |
| 233 | + $field = self::__fieldExtract($database,$field); | |
| 234 | + if (is_null($field)) { | |
| 235 | + return NULL; | |
| 236 | + } | |
| 297 | 237 | |
| 238 | + // reduce the database to a set of rows that match all the criteria | |
| 239 | + $database = self::__filter($database,$criteria); | |
| 240 | + // extract an array of values for the requested column | |
| 241 | + $colData = array(); | |
| 242 | + foreach($database as $row) { | |
| 243 | + $colData[] = $row[$field]; | |
| 244 | + } | |
| 298 | 245 | |
| 299 | - /** | |
| 300 | - * DGET | |
| 301 | - * | |
| 302 | - * Extracts a single value from a column of a list or database that matches conditions that you | |
| 303 | - * specify. | |
| 304 | - * | |
| 305 | - * Excel Function: | |
| 306 | - * DGET(database,field,criteria) | |
| 307 | - * | |
| 308 | - * @access public | |
| 309 | - * @category Database Functions | |
| 310 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 311 | - * A database is a list of related data in which rows of related | |
| 312 | - * information are records, and columns of data are fields. The | |
| 313 | - * first row of the list contains labels for each column. | |
| 314 | - * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 315 | - * column label enclosed between double quotation marks, such as | |
| 316 | - * "Age" or "Yield," or a number (without quotation marks) that | |
| 317 | - * represents the position of the column within the list: 1 for | |
| 318 | - * the first column, 2 for the second column, and so on. | |
| 319 | - * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 320 | - * You can use any range for the criteria argument, as long as it | |
| 321 | - * includes at least one column label and at least one cell below | |
| 322 | - * the column label in which you specify a condition for the | |
| 323 | - * column. | |
| 324 | - * @return mixed | |
| 325 | - * | |
| 326 | - */ | |
| 327 | - public static function DGET($database, $field, $criteria) | |
| 328 | - { | |
| 329 | - $field = self::fieldExtract($database, $field); | |
| 330 | - if (is_null($field)) { | |
| 331 | - return null; | |
| 332 | - } | |
| 246 | + // Return | |
| 247 | + return PHPExcel_Calculation_Statistical::COUNT($colData); | |
| 248 | + } // function DCOUNT() | |
| 333 | 249 | |
| 334 | - // Return | |
| 335 | - $colData = self::getFilteredColumn($database, $field, $criteria); | |
| 336 | - if (count($colData) > 1) { | |
| 337 | - return PHPExcel_Calculation_Functions::NaN(); | |
| 338 | - } | |
| 339 | 250 | |
| 340 | - return $colData[0]; | |
| 341 | - } | |
| 251 | + /** | |
| 252 | + * DCOUNTA | |
| 253 | + * | |
| 254 | + * Counts the nonblank cells in a column of a list or database that match conditions that you specify. | |
| 255 | + * | |
| 256 | + * Excel Function: | |
| 257 | + * DCOUNTA(database,[field],criteria) | |
| 258 | + * | |
| 259 | + * @access public | |
| 260 | + * @category Database Functions | |
| 261 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 262 | + * A database is a list of related data in which rows of related | |
| 263 | + * information are records, and columns of data are fields. The | |
| 264 | + * first row of the list contains labels for each column. | |
| 265 | + * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 266 | + * column label enclosed between double quotation marks, such as | |
| 267 | + * "Age" or "Yield," or a number (without quotation marks) that | |
| 268 | + * represents the position of the column within the list: 1 for | |
| 269 | + * the first column, 2 for the second column, and so on. | |
| 270 | + * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 271 | + * You can use any range for the criteria argument, as long as it | |
| 272 | + * includes at least one column label and at least one cell below | |
| 273 | + * the column label in which you specify a condition for the | |
| 274 | + * column. | |
| 275 | + * @return integer | |
| 276 | + * | |
| 277 | + * @TODO The field argument is optional. If field is omitted, DCOUNTA counts all records in the | |
| 278 | + * database that match the criteria. | |
| 279 | + * | |
| 280 | + */ | |
| 281 | + public static function DCOUNTA($database,$field,$criteria) { | |
| 282 | + $field = self::__fieldExtract($database,$field); | |
| 283 | + if (is_null($field)) { | |
| 284 | + return NULL; | |
| 285 | + } | |
| 342 | 286 | |
| 287 | + // reduce the database to a set of rows that match all the criteria | |
| 288 | + $database = self::__filter($database,$criteria); | |
| 289 | + // extract an array of values for the requested column | |
| 290 | + $colData = array(); | |
| 291 | + foreach($database as $row) { | |
| 292 | + $colData[] = $row[$field]; | |
| 293 | + } | |
| 343 | 294 | |
| 344 | - /** | |
| 345 | - * DMAX | |
| 346 | - * | |
| 347 | - * Returns the largest number in a column of a list or database that matches conditions you that | |
| 348 | - * specify. | |
| 349 | - * | |
| 350 | - * Excel Function: | |
| 351 | - * DMAX(database,field,criteria) | |
| 352 | - * | |
| 353 | - * @access public | |
| 354 | - * @category Database Functions | |
| 355 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 356 | - * A database is a list of related data in which rows of related | |
| 357 | - * information are records, and columns of data are fields. The | |
| 358 | - * first row of the list contains labels for each column. | |
| 359 | - * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 360 | - * column label enclosed between double quotation marks, such as | |
| 361 | - * "Age" or "Yield," or a number (without quotation marks) that | |
| 362 | - * represents the position of the column within the list: 1 for | |
| 363 | - * the first column, 2 for the second column, and so on. | |
| 364 | - * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 365 | - * You can use any range for the criteria argument, as long as it | |
| 366 | - * includes at least one column label and at least one cell below | |
| 367 | - * the column label in which you specify a condition for the | |
| 368 | - * column. | |
| 369 | - * @return float | |
| 370 | - * | |
| 371 | - */ | |
| 372 | - public static function DMAX($database, $field, $criteria) | |
| 373 | - { | |
| 374 | - $field = self::fieldExtract($database, $field); | |
| 375 | - if (is_null($field)) { | |
| 376 | - return null; | |
| 377 | - } | |
| 295 | + // Return | |
| 296 | + return PHPExcel_Calculation_Statistical::COUNTA($colData); | |
| 297 | + } // function DCOUNTA() | |
| 378 | 298 | |
| 379 | - // Return | |
| 380 | - return PHPExcel_Calculation_Statistical::MAX( | |
| 381 | - self::getFilteredColumn($database, $field, $criteria) | |
| 382 | - ); | |
| 383 | - } | |
| 384 | 299 | |
| 300 | + /** | |
| 301 | + * DGET | |
| 302 | + * | |
| 303 | + * Extracts a single value from a column of a list or database that matches conditions that you | |
| 304 | + * specify. | |
| 305 | + * | |
| 306 | + * Excel Function: | |
| 307 | + * DGET(database,field,criteria) | |
| 308 | + * | |
| 309 | + * @access public | |
| 310 | + * @category Database Functions | |
| 311 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 312 | + * A database is a list of related data in which rows of related | |
| 313 | + * information are records, and columns of data are fields. The | |
| 314 | + * first row of the list contains labels for each column. | |
| 315 | + * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 316 | + * column label enclosed between double quotation marks, such as | |
| 317 | + * "Age" or "Yield," or a number (without quotation marks) that | |
| 318 | + * represents the position of the column within the list: 1 for | |
| 319 | + * the first column, 2 for the second column, and so on. | |
| 320 | + * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 321 | + * You can use any range for the criteria argument, as long as it | |
| 322 | + * includes at least one column label and at least one cell below | |
| 323 | + * the column label in which you specify a condition for the | |
| 324 | + * column. | |
| 325 | + * @return mixed | |
| 326 | + * | |
| 327 | + */ | |
| 328 | + public static function DGET($database,$field,$criteria) { | |
| 329 | + $field = self::__fieldExtract($database,$field); | |
| 330 | + if (is_null($field)) { | |
| 331 | + return NULL; | |
| 332 | + } | |
| 385 | 333 | |
| 386 | - /** | |
| 387 | - * DMIN | |
| 388 | - * | |
| 389 | - * Returns the smallest number in a column of a list or database that matches conditions you that | |
| 390 | - * specify. | |
| 391 | - * | |
| 392 | - * Excel Function: | |
| 393 | - * DMIN(database,field,criteria) | |
| 394 | - * | |
| 395 | - * @access public | |
| 396 | - * @category Database Functions | |
| 397 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 398 | - * A database is a list of related data in which rows of related | |
| 399 | - * information are records, and columns of data are fields. The | |
| 400 | - * first row of the list contains labels for each column. | |
| 401 | - * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 402 | - * column label enclosed between double quotation marks, such as | |
| 403 | - * "Age" or "Yield," or a number (without quotation marks) that | |
| 404 | - * represents the position of the column within the list: 1 for | |
| 405 | - * the first column, 2 for the second column, and so on. | |
| 406 | - * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 407 | - * You can use any range for the criteria argument, as long as it | |
| 408 | - * includes at least one column label and at least one cell below | |
| 409 | - * the column label in which you specify a condition for the | |
| 410 | - * column. | |
| 411 | - * @return float | |
| 412 | - * | |
| 413 | - */ | |
| 414 | - public static function DMIN($database, $field, $criteria) | |
| 415 | - { | |
| 416 | - $field = self::fieldExtract($database, $field); | |
| 417 | - if (is_null($field)) { | |
| 418 | - return null; | |
| 419 | - } | |
| 334 | + // reduce the database to a set of rows that match all the criteria | |
| 335 | + $database = self::__filter($database,$criteria); | |
| 336 | + // extract an array of values for the requested column | |
| 337 | + $colData = array(); | |
| 338 | + foreach($database as $row) { | |
| 339 | + $colData[] = $row[$field]; | |
| 340 | + } | |
| 420 | 341 | |
| 421 | - // Return | |
| 422 | - return PHPExcel_Calculation_Statistical::MIN( | |
| 423 | - self::getFilteredColumn($database, $field, $criteria) | |
| 424 | - ); | |
| 425 | - } | |
| 342 | + // Return | |
| 343 | + if (count($colData) > 1) { | |
| 344 | + return PHPExcel_Calculation_Functions::NaN(); | |
| 345 | + } | |
| 426 | 346 | |
| 347 | + return $colData[0]; | |
| 348 | + } // function DGET() | |
| 427 | 349 | |
| 428 | - /** | |
| 429 | - * DPRODUCT | |
| 430 | - * | |
| 431 | - * Multiplies the values in a column of a list or database that match conditions that you specify. | |
| 432 | - * | |
| 433 | - * Excel Function: | |
| 434 | - * DPRODUCT(database,field,criteria) | |
| 435 | - * | |
| 436 | - * @access public | |
| 437 | - * @category Database Functions | |
| 438 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 439 | - * A database is a list of related data in which rows of related | |
| 440 | - * information are records, and columns of data are fields. The | |
| 441 | - * first row of the list contains labels for each column. | |
| 442 | - * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 443 | - * column label enclosed between double quotation marks, such as | |
| 444 | - * "Age" or "Yield," or a number (without quotation marks) that | |
| 445 | - * represents the position of the column within the list: 1 for | |
| 446 | - * the first column, 2 for the second column, and so on. | |
| 447 | - * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 448 | - * You can use any range for the criteria argument, as long as it | |
| 449 | - * includes at least one column label and at least one cell below | |
| 450 | - * the column label in which you specify a condition for the | |
| 451 | - * column. | |
| 452 | - * @return float | |
| 453 | - * | |
| 454 | - */ | |
| 455 | - public static function DPRODUCT($database, $field, $criteria) | |
| 456 | - { | |
| 457 | - $field = self::fieldExtract($database, $field); | |
| 458 | - if (is_null($field)) { | |
| 459 | - return null; | |
| 460 | - } | |
| 461 | 350 | |
| 462 | - // Return | |
| 463 | - return PHPExcel_Calculation_MathTrig::PRODUCT( | |
| 464 | - self::getFilteredColumn($database, $field, $criteria) | |
| 465 | - ); | |
| 466 | - } | |
| 351 | + /** | |
| 352 | + * DMAX | |
| 353 | + * | |
| 354 | + * Returns the largest number in a column of a list or database that matches conditions you that | |
| 355 | + * specify. | |
| 356 | + * | |
| 357 | + * Excel Function: | |
| 358 | + * DMAX(database,field,criteria) | |
| 359 | + * | |
| 360 | + * @access public | |
| 361 | + * @category Database Functions | |
| 362 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 363 | + * A database is a list of related data in which rows of related | |
| 364 | + * information are records, and columns of data are fields. The | |
| 365 | + * first row of the list contains labels for each column. | |
| 366 | + * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 367 | + * column label enclosed between double quotation marks, such as | |
| 368 | + * "Age" or "Yield," or a number (without quotation marks) that | |
| 369 | + * represents the position of the column within the list: 1 for | |
| 370 | + * the first column, 2 for the second column, and so on. | |
| 371 | + * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 372 | + * You can use any range for the criteria argument, as long as it | |
| 373 | + * includes at least one column label and at least one cell below | |
| 374 | + * the column label in which you specify a condition for the | |
| 375 | + * column. | |
| 376 | + * @return float | |
| 377 | + * | |
| 378 | + */ | |
| 379 | + public static function DMAX($database,$field,$criteria) { | |
| 380 | + $field = self::__fieldExtract($database,$field); | |
| 381 | + if (is_null($field)) { | |
| 382 | + return NULL; | |
| 383 | + } | |
| 467 | 384 | |
| 385 | + // reduce the database to a set of rows that match all the criteria | |
| 386 | + $database = self::__filter($database,$criteria); | |
| 387 | + // extract an array of values for the requested column | |
| 388 | + $colData = array(); | |
| 389 | + foreach($database as $row) { | |
| 390 | + $colData[] = $row[$field]; | |
| 391 | + } | |
| 468 | 392 | |
| 469 | - /** | |
| 470 | - * DSTDEV | |
| 471 | - * | |
| 472 | - * Estimates the standard deviation of a population based on a sample by using the numbers in a | |
| 473 | - * column of a list or database that match conditions that you specify. | |
| 474 | - * | |
| 475 | - * Excel Function: | |
| 476 | - * DSTDEV(database,field,criteria) | |
| 477 | - * | |
| 478 | - * @access public | |
| 479 | - * @category Database Functions | |
| 480 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 481 | - * A database is a list of related data in which rows of related | |
| 482 | - * information are records, and columns of data are fields. The | |
| 483 | - * first row of the list contains labels for each column. | |
| 484 | - * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 485 | - * column label enclosed between double quotation marks, such as | |
| 486 | - * "Age" or "Yield," or a number (without quotation marks) that | |
| 487 | - * represents the position of the column within the list: 1 for | |
| 488 | - * the first column, 2 for the second column, and so on. | |
| 489 | - * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 490 | - * You can use any range for the criteria argument, as long as it | |
| 491 | - * includes at least one column label and at least one cell below | |
| 492 | - * the column label in which you specify a condition for the | |
| 493 | - * column. | |
| 494 | - * @return float | |
| 495 | - * | |
| 496 | - */ | |
| 497 | - public static function DSTDEV($database, $field, $criteria) | |
| 498 | - { | |
| 499 | - $field = self::fieldExtract($database, $field); | |
| 500 | - if (is_null($field)) { | |
| 501 | - return null; | |
| 502 | - } | |
| 393 | + // Return | |
| 394 | + return PHPExcel_Calculation_Statistical::MAX($colData); | |
| 395 | + } // function DMAX() | |
| 503 | 396 | |
| 504 | - // Return | |
| 505 | - return PHPExcel_Calculation_Statistical::STDEV( | |
| 506 | - self::getFilteredColumn($database, $field, $criteria) | |
| 507 | - ); | |
| 508 | - } | |
| 509 | 397 | |
| 398 | + /** | |
| 399 | + * DMIN | |
| 400 | + * | |
| 401 | + * Returns the smallest number in a column of a list or database that matches conditions you that | |
| 402 | + * specify. | |
| 403 | + * | |
| 404 | + * Excel Function: | |
| 405 | + * DMIN(database,field,criteria) | |
| 406 | + * | |
| 407 | + * @access public | |
| 408 | + * @category Database Functions | |
| 409 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 410 | + * A database is a list of related data in which rows of related | |
| 411 | + * information are records, and columns of data are fields. The | |
| 412 | + * first row of the list contains labels for each column. | |
| 413 | + * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 414 | + * column label enclosed between double quotation marks, such as | |
| 415 | + * "Age" or "Yield," or a number (without quotation marks) that | |
| 416 | + * represents the position of the column within the list: 1 for | |
| 417 | + * the first column, 2 for the second column, and so on. | |
| 418 | + * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 419 | + * You can use any range for the criteria argument, as long as it | |
| 420 | + * includes at least one column label and at least one cell below | |
| 421 | + * the column label in which you specify a condition for the | |
| 422 | + * column. | |
| 423 | + * @return float | |
| 424 | + * | |
| 425 | + */ | |
| 426 | + public static function DMIN($database,$field,$criteria) { | |
| 427 | + $field = self::__fieldExtract($database,$field); | |
| 428 | + if (is_null($field)) { | |
| 429 | + return NULL; | |
| 430 | + } | |
| 510 | 431 | |
| 511 | - /** | |
| 512 | - * DSTDEVP | |
| 513 | - * | |
| 514 | - * Calculates the standard deviation of a population based on the entire population by using the | |
| 515 | - * numbers in a column of a list or database that match conditions that you specify. | |
| 516 | - * | |
| 517 | - * Excel Function: | |
| 518 | - * DSTDEVP(database,field,criteria) | |
| 519 | - * | |
| 520 | - * @access public | |
| 521 | - * @category Database Functions | |
| 522 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 523 | - * A database is a list of related data in which rows of related | |
| 524 | - * information are records, and columns of data are fields. The | |
| 525 | - * first row of the list contains labels for each column. | |
| 526 | - * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 527 | - * column label enclosed between double quotation marks, such as | |
| 528 | - * "Age" or "Yield," or a number (without quotation marks) that | |
| 529 | - * represents the position of the column within the list: 1 for | |
| 530 | - * the first column, 2 for the second column, and so on. | |
| 531 | - * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 532 | - * You can use any range for the criteria argument, as long as it | |
| 533 | - * includes at least one column label and at least one cell below | |
| 534 | - * the column label in which you specify a condition for the | |
| 535 | - * column. | |
| 536 | - * @return float | |
| 537 | - * | |
| 538 | - */ | |
| 539 | - public static function DSTDEVP($database, $field, $criteria) | |
| 540 | - { | |
| 541 | - $field = self::fieldExtract($database, $field); | |
| 542 | - if (is_null($field)) { | |
| 543 | - return null; | |
| 544 | - } | |
| 432 | + // reduce the database to a set of rows that match all the criteria | |
| 433 | + $database = self::__filter($database,$criteria); | |
| 434 | + // extract an array of values for the requested column | |
| 435 | + $colData = array(); | |
| 436 | + foreach($database as $row) { | |
| 437 | + $colData[] = $row[$field]; | |
| 438 | + } | |
| 545 | 439 | |
| 546 | - // Return | |
| 547 | - return PHPExcel_Calculation_Statistical::STDEVP( | |
| 548 | - self::getFilteredColumn($database, $field, $criteria) | |
| 549 | - ); | |
| 550 | - } | |
| 440 | + // Return | |
| 441 | + return PHPExcel_Calculation_Statistical::MIN($colData); | |
| 442 | + } // function DMIN() | |
| 551 | 443 | |
| 552 | 444 | |
| 553 | - /** | |
| 554 | - * DSUM | |
| 555 | - * | |
| 556 | - * Adds the numbers in a column of a list or database that match conditions that you specify. | |
| 557 | - * | |
| 558 | - * Excel Function: | |
| 559 | - * DSUM(database,field,criteria) | |
| 560 | - * | |
| 561 | - * @access public | |
| 562 | - * @category Database Functions | |
| 563 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 564 | - * A database is a list of related data in which rows of related | |
| 565 | - * information are records, and columns of data are fields. The | |
| 566 | - * first row of the list contains labels for each column. | |
| 567 | - * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 568 | - * column label enclosed between double quotation marks, such as | |
| 569 | - * "Age" or "Yield," or a number (without quotation marks) that | |
| 570 | - * represents the position of the column within the list: 1 for | |
| 571 | - * the first column, 2 for the second column, and so on. | |
| 572 | - * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 573 | - * You can use any range for the criteria argument, as long as it | |
| 574 | - * includes at least one column label and at least one cell below | |
| 575 | - * the column label in which you specify a condition for the | |
| 576 | - * column. | |
| 577 | - * @return float | |
| 578 | - * | |
| 579 | - */ | |
| 580 | - public static function DSUM($database, $field, $criteria) | |
| 581 | - { | |
| 582 | - $field = self::fieldExtract($database, $field); | |
| 583 | - if (is_null($field)) { | |
| 584 | - return null; | |
| 585 | - } | |
| 445 | + /** | |
| 446 | + * DPRODUCT | |
| 447 | + * | |
| 448 | + * Multiplies the values in a column of a list or database that match conditions that you specify. | |
| 449 | + * | |
| 450 | + * Excel Function: | |
| 451 | + * DPRODUCT(database,field,criteria) | |
| 452 | + * | |
| 453 | + * @access public | |
| 454 | + * @category Database Functions | |
| 455 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 456 | + * A database is a list of related data in which rows of related | |
| 457 | + * information are records, and columns of data are fields. The | |
| 458 | + * first row of the list contains labels for each column. | |
| 459 | + * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 460 | + * column label enclosed between double quotation marks, such as | |
| 461 | + * "Age" or "Yield," or a number (without quotation marks) that | |
| 462 | + * represents the position of the column within the list: 1 for | |
| 463 | + * the first column, 2 for the second column, and so on. | |
| 464 | + * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 465 | + * You can use any range for the criteria argument, as long as it | |
| 466 | + * includes at least one column label and at least one cell below | |
| 467 | + * the column label in which you specify a condition for the | |
| 468 | + * column. | |
| 469 | + * @return float | |
| 470 | + * | |
| 471 | + */ | |
| 472 | + public static function DPRODUCT($database,$field,$criteria) { | |
| 473 | + $field = self::__fieldExtract($database,$field); | |
| 474 | + if (is_null($field)) { | |
| 475 | + return NULL; | |
| 476 | + } | |
| 586 | 477 | |
| 587 | - // Return | |
| 588 | - return PHPExcel_Calculation_MathTrig::SUM( | |
| 589 | - self::getFilteredColumn($database, $field, $criteria) | |
| 590 | - ); | |
| 591 | - } | |
| 478 | + // reduce the database to a set of rows that match all the criteria | |
| 479 | + $database = self::__filter($database,$criteria); | |
| 480 | + // extract an array of values for the requested column | |
| 481 | + $colData = array(); | |
| 482 | + foreach($database as $row) { | |
| 483 | + $colData[] = $row[$field]; | |
| 484 | + } | |
| 592 | 485 | |
| 486 | + // Return | |
| 487 | + return PHPExcel_Calculation_MathTrig::PRODUCT($colData); | |
| 488 | + } // function DPRODUCT() | |
| 593 | 489 | |
| 594 | - /** | |
| 595 | - * DVAR | |
| 596 | - * | |
| 597 | - * Estimates the variance of a population based on a sample by using the numbers in a column | |
| 598 | - * of a list or database that match conditions that you specify. | |
| 599 | - * | |
| 600 | - * Excel Function: | |
| 601 | - * DVAR(database,field,criteria) | |
| 602 | - * | |
| 603 | - * @access public | |
| 604 | - * @category Database Functions | |
| 605 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 606 | - * A database is a list of related data in which rows of related | |
| 607 | - * information are records, and columns of data are fields. The | |
| 608 | - * first row of the list contains labels for each column. | |
| 609 | - * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 610 | - * column label enclosed between double quotation marks, such as | |
| 611 | - * "Age" or "Yield," or a number (without quotation marks) that | |
| 612 | - * represents the position of the column within the list: 1 for | |
| 613 | - * the first column, 2 for the second column, and so on. | |
| 614 | - * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 615 | - * You can use any range for the criteria argument, as long as it | |
| 616 | - * includes at least one column label and at least one cell below | |
| 617 | - * the column label in which you specify a condition for the | |
| 618 | - * column. | |
| 619 | - * @return float | |
| 620 | - * | |
| 621 | - */ | |
| 622 | - public static function DVAR($database, $field, $criteria) | |
| 623 | - { | |
| 624 | - $field = self::fieldExtract($database, $field); | |
| 625 | - if (is_null($field)) { | |
| 626 | - return null; | |
| 627 | - } | |
| 628 | 490 | |
| 629 | - // Return | |
| 630 | - return PHPExcel_Calculation_Statistical::VARFunc( | |
| 631 | - self::getFilteredColumn($database, $field, $criteria) | |
| 632 | - ); | |
| 633 | - } | |
| 491 | + /** | |
| 492 | + * DSTDEV | |
| 493 | + * | |
| 494 | + * Estimates the standard deviation of a population based on a sample by using the numbers in a | |
| 495 | + * column of a list or database that match conditions that you specify. | |
| 496 | + * | |
| 497 | + * Excel Function: | |
| 498 | + * DSTDEV(database,field,criteria) | |
| 499 | + * | |
| 500 | + * @access public | |
| 501 | + * @category Database Functions | |
| 502 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 503 | + * A database is a list of related data in which rows of related | |
| 504 | + * information are records, and columns of data are fields. The | |
| 505 | + * first row of the list contains labels for each column. | |
| 506 | + * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 507 | + * column label enclosed between double quotation marks, such as | |
| 508 | + * "Age" or "Yield," or a number (without quotation marks) that | |
| 509 | + * represents the position of the column within the list: 1 for | |
| 510 | + * the first column, 2 for the second column, and so on. | |
| 511 | + * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 512 | + * You can use any range for the criteria argument, as long as it | |
| 513 | + * includes at least one column label and at least one cell below | |
| 514 | + * the column label in which you specify a condition for the | |
| 515 | + * column. | |
| 516 | + * @return float | |
| 517 | + * | |
| 518 | + */ | |
| 519 | + public static function DSTDEV($database,$field,$criteria) { | |
| 520 | + $field = self::__fieldExtract($database,$field); | |
| 521 | + if (is_null($field)) { | |
| 522 | + return NULL; | |
| 523 | + } | |
| 634 | 524 | |
| 525 | + // reduce the database to a set of rows that match all the criteria | |
| 526 | + $database = self::__filter($database,$criteria); | |
| 527 | + // extract an array of values for the requested column | |
| 528 | + $colData = array(); | |
| 529 | + foreach($database as $row) { | |
| 530 | + $colData[] = $row[$field]; | |
| 531 | + } | |
| 635 | 532 | |
| 636 | - /** | |
| 637 | - * DVARP | |
| 638 | - * | |
| 639 | - * Calculates the variance of a population based on the entire population by using the numbers | |
| 640 | - * in a column of a list or database that match conditions that you specify. | |
| 641 | - * | |
| 642 | - * Excel Function: | |
| 643 | - * DVARP(database,field,criteria) | |
| 644 | - * | |
| 645 | - * @access public | |
| 646 | - * @category Database Functions | |
| 647 | - * @param mixed[] $database The range of cells that makes up the list or database. | |
| 648 | - * A database is a list of related data in which rows of related | |
| 649 | - * information are records, and columns of data are fields. The | |
| 650 | - * first row of the list contains labels for each column. | |
| 651 | - * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 652 | - * column label enclosed between double quotation marks, such as | |
| 653 | - * "Age" or "Yield," or a number (without quotation marks) that | |
| 654 | - * represents the position of the column within the list: 1 for | |
| 655 | - * the first column, 2 for the second column, and so on. | |
| 656 | - * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 657 | - * You can use any range for the criteria argument, as long as it | |
| 658 | - * includes at least one column label and at least one cell below | |
| 659 | - * the column label in which you specify a condition for the | |
| 660 | - * column. | |
| 661 | - * @return float | |
| 662 | - * | |
| 663 | - */ | |
| 664 | - public static function DVARP($database, $field, $criteria) | |
| 665 | - { | |
| 666 | - $field = self::fieldExtract($database, $field); | |
| 667 | - if (is_null($field)) { | |
| 668 | - return null; | |
| 669 | - } | |
| 533 | + // Return | |
| 534 | + return PHPExcel_Calculation_Statistical::STDEV($colData); | |
| 535 | + } // function DSTDEV() | |
| 670 | 536 | |
| 671 | - // Return | |
| 672 | - return PHPExcel_Calculation_Statistical::VARP( | |
| 673 | - self::getFilteredColumn($database, $field, $criteria) | |
| 674 | - ); | |
| 675 | - } | |
| 676 | -} | |
| 537 | + | |
| 538 | + /** | |
| 539 | + * DSTDEVP | |
| 540 | + * | |
| 541 | + * Calculates the standard deviation of a population based on the entire population by using the | |
| 542 | + * numbers in a column of a list or database that match conditions that you specify. | |
| 543 | + * | |
| 544 | + * Excel Function: | |
| 545 | + * DSTDEVP(database,field,criteria) | |
| 546 | + * | |
| 547 | + * @access public | |
| 548 | + * @category Database Functions | |
| 549 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 550 | + * A database is a list of related data in which rows of related | |
| 551 | + * information are records, and columns of data are fields. The | |
| 552 | + * first row of the list contains labels for each column. | |
| 553 | + * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 554 | + * column label enclosed between double quotation marks, such as | |
| 555 | + * "Age" or "Yield," or a number (without quotation marks) that | |
| 556 | + * represents the position of the column within the list: 1 for | |
| 557 | + * the first column, 2 for the second column, and so on. | |
| 558 | + * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 559 | + * You can use any range for the criteria argument, as long as it | |
| 560 | + * includes at least one column label and at least one cell below | |
| 561 | + * the column label in which you specify a condition for the | |
| 562 | + * column. | |
| 563 | + * @return float | |
| 564 | + * | |
| 565 | + */ | |
| 566 | + public static function DSTDEVP($database,$field,$criteria) { | |
| 567 | + $field = self::__fieldExtract($database,$field); | |
| 568 | + if (is_null($field)) { | |
| 569 | + return NULL; | |
| 570 | + } | |
| 571 | + | |
| 572 | + // reduce the database to a set of rows that match all the criteria | |
| 573 | + $database = self::__filter($database,$criteria); | |
| 574 | + // extract an array of values for the requested column | |
| 575 | + $colData = array(); | |
| 576 | + foreach($database as $row) { | |
| 577 | + $colData[] = $row[$field]; | |
| 578 | + } | |
| 579 | + | |
| 580 | + // Return | |
| 581 | + return PHPExcel_Calculation_Statistical::STDEVP($colData); | |
| 582 | + } // function DSTDEVP() | |
| 583 | + | |
| 584 | + | |
| 585 | + /** | |
| 586 | + * DSUM | |
| 587 | + * | |
| 588 | + * Adds the numbers in a column of a list or database that match conditions that you specify. | |
| 589 | + * | |
| 590 | + * Excel Function: | |
| 591 | + * DSUM(database,field,criteria) | |
| 592 | + * | |
| 593 | + * @access public | |
| 594 | + * @category Database Functions | |
| 595 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 596 | + * A database is a list of related data in which rows of related | |
| 597 | + * information are records, and columns of data are fields. The | |
| 598 | + * first row of the list contains labels for each column. | |
| 599 | + * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 600 | + * column label enclosed between double quotation marks, such as | |
| 601 | + * "Age" or "Yield," or a number (without quotation marks) that | |
| 602 | + * represents the position of the column within the list: 1 for | |
| 603 | + * the first column, 2 for the second column, and so on. | |
| 604 | + * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 605 | + * You can use any range for the criteria argument, as long as it | |
| 606 | + * includes at least one column label and at least one cell below | |
| 607 | + * the column label in which you specify a condition for the | |
| 608 | + * column. | |
| 609 | + * @return float | |
| 610 | + * | |
| 611 | + */ | |
| 612 | + public static function DSUM($database,$field,$criteria) { | |
| 613 | + $field = self::__fieldExtract($database,$field); | |
| 614 | + if (is_null($field)) { | |
| 615 | + return NULL; | |
| 616 | + } | |
| 617 | + | |
| 618 | + // reduce the database to a set of rows that match all the criteria | |
| 619 | + $database = self::__filter($database,$criteria); | |
| 620 | + // extract an array of values for the requested column | |
| 621 | + $colData = array(); | |
| 622 | + foreach($database as $row) { | |
| 623 | + $colData[] = $row[$field]; | |
| 624 | + } | |
| 625 | + | |
| 626 | + // Return | |
| 627 | + return PHPExcel_Calculation_MathTrig::SUM($colData); | |
| 628 | + } // function DSUM() | |
| 629 | + | |
| 630 | + | |
| 631 | + /** | |
| 632 | + * DVAR | |
| 633 | + * | |
| 634 | + * Estimates the variance of a population based on a sample by using the numbers in a column | |
| 635 | + * of a list or database that match conditions that you specify. | |
| 636 | + * | |
| 637 | + * Excel Function: | |
| 638 | + * DVAR(database,field,criteria) | |
| 639 | + * | |
| 640 | + * @access public | |
| 641 | + * @category Database Functions | |
| 642 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 643 | + * A database is a list of related data in which rows of related | |
| 644 | + * information are records, and columns of data are fields. The | |
| 645 | + * first row of the list contains labels for each column. | |
| 646 | + * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 647 | + * column label enclosed between double quotation marks, such as | |
| 648 | + * "Age" or "Yield," or a number (without quotation marks) that | |
| 649 | + * represents the position of the column within the list: 1 for | |
| 650 | + * the first column, 2 for the second column, and so on. | |
| 651 | + * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 652 | + * You can use any range for the criteria argument, as long as it | |
| 653 | + * includes at least one column label and at least one cell below | |
| 654 | + * the column label in which you specify a condition for the | |
| 655 | + * column. | |
| 656 | + * @return float | |
| 657 | + * | |
| 658 | + */ | |
| 659 | + public static function DVAR($database,$field,$criteria) { | |
| 660 | + $field = self::__fieldExtract($database,$field); | |
| 661 | + if (is_null($field)) { | |
| 662 | + return NULL; | |
| 663 | + } | |
| 664 | + | |
| 665 | + // reduce the database to a set of rows that match all the criteria | |
| 666 | + $database = self::__filter($database,$criteria); | |
| 667 | + // extract an array of values for the requested column | |
| 668 | + $colData = array(); | |
| 669 | + foreach($database as $row) { | |
| 670 | + $colData[] = $row[$field]; | |
| 671 | + } | |
| 672 | + | |
| 673 | + // Return | |
| 674 | + return PHPExcel_Calculation_Statistical::VARFunc($colData); | |
| 675 | + } // function DVAR() | |
| 676 | + | |
| 677 | + | |
| 678 | + /** | |
| 679 | + * DVARP | |
| 680 | + * | |
| 681 | + * Calculates the variance of a population based on the entire population by using the numbers | |
| 682 | + * in a column of a list or database that match conditions that you specify. | |
| 683 | + * | |
| 684 | + * Excel Function: | |
| 685 | + * DVARP(database,field,criteria) | |
| 686 | + * | |
| 687 | + * @access public | |
| 688 | + * @category Database Functions | |
| 689 | + * @param mixed[] $database The range of cells that makes up the list or database. | |
| 690 | + * A database is a list of related data in which rows of related | |
| 691 | + * information are records, and columns of data are fields. The | |
| 692 | + * first row of the list contains labels for each column. | |
| 693 | + * @param string|integer $field Indicates which column is used in the function. Enter the | |
| 694 | + * column label enclosed between double quotation marks, such as | |
| 695 | + * "Age" or "Yield," or a number (without quotation marks) that | |
| 696 | + * represents the position of the column within the list: 1 for | |
| 697 | + * the first column, 2 for the second column, and so on. | |
| 698 | + * @param mixed[] $criteria The range of cells that contains the conditions you specify. | |
| 699 | + * You can use any range for the criteria argument, as long as it | |
| 700 | + * includes at least one column label and at least one cell below | |
| 701 | + * the column label in which you specify a condition for the | |
| 702 | + * column. | |
| 703 | + * @return float | |
| 704 | + * | |
| 705 | + */ | |
| 706 | + public static function DVARP($database,$field,$criteria) { | |
| 707 | + $field = self::__fieldExtract($database,$field); | |
| 708 | + if (is_null($field)) { | |
| 709 | + return NULL; | |
| 710 | + } | |
| 711 | + | |
| 712 | + // reduce the database to a set of rows that match all the criteria | |
| 713 | + $database = self::__filter($database,$criteria); | |
| 714 | + // extract an array of values for the requested column | |
| 715 | + $colData = array(); | |
| 716 | + foreach($database as $row) { | |
| 717 | + $colData[] = $row[$field]; | |
| 718 | + } | |
| 719 | + | |
| 720 | + // Return | |
| 721 | + return PHPExcel_Calculation_Statistical::VARP($colData); | |
| 722 | + } // function DVARP() | |
| 723 | + | |
| 724 | + | |
| 725 | +} // class PHPExcel_Calculation_Database | |