30 if (!defined(
'PHPEXCEL_ROOT')) {
34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../../');
35 require(PHPEXCEL_ROOT .
'PHPExcel/Autoloader.php');
51 $fieldNames = array_map(
'strtoupper',array_shift($database));
53 if (is_numeric($field)) {
54 $keys = array_keys($fieldNames);
55 return $keys[$field-1];
57 $key = array_search($field,$fieldNames);
58 return ($key) ? $key : null;
61 private static function __filter($database,$criteria) {
62 $fieldNames = array_shift($database);
63 $criteriaNames = array_shift($criteria);
66 $testConditions = $testValues = array();
67 $testConditionsCount = 0;
68 foreach($criteriaNames as $key => $criteriaName) {
69 $testCondition = array();
70 $testConditionCount = 0;
71 foreach($criteria as
$row => $criterion) {
72 if ($criterion[$key] >
'') {
74 $testConditionCount++;
77 if ($testConditionCount > 1) {
78 $testConditions[] =
'OR('.implode(
',',$testCondition).
')';
79 $testConditionsCount++;
80 } elseif($testConditionCount == 1) {
81 $testConditions[] = $testCondition[0];
82 $testConditionsCount++;
85 if ($testConditionsCount > 1) {
86 $testConditionSet =
'AND('.implode(
',',$testConditions).
')';
87 } elseif($testConditionsCount == 1) {
88 $testConditionSet = $testConditions[0];
92 foreach($database as $dataRow => $dataValues) {
94 $testConditionList = $testConditionSet;
95 foreach($criteriaNames as $key => $criteriaName) {
96 $k = array_search($criteriaName,$fieldNames);
97 if (isset($dataValues[$k])) {
98 $dataValue = $dataValues[$k];
100 $testConditionList = str_replace(
'[:'.$criteriaName.
']',$dataValue,$testConditionList);
107 unset($database[$dataRow]);
119 public static function DAVERAGE($database,$field,$criteria) {
121 if (is_null($field)) {
129 foreach($database as
$row) {
130 $colData[] = $row[$field];
141 public static function DCOUNT($database,$field,$criteria) {
143 if (is_null($field)) {
151 foreach($database as
$row) {
152 $colData[] = $row[$field];
163 public static function DCOUNTA($database,$field,$criteria) {
165 if (is_null($field)) {
173 foreach($database as
$row) {
174 $colData[] = $row[$field];
185 public static function DGET($database,$field,$criteria) {
187 if (is_null($field)) {
195 foreach($database as
$row) {
196 $colData[] = $row[$field];
200 if (count($colData) > 1) {
211 public static function DMAX($database,$field,$criteria) {
213 if (is_null($field)) {
221 foreach($database as
$row) {
222 $colData[] = $row[$field];
233 public static function DMIN($database,$field,$criteria) {
235 if (is_null($field)) {
243 foreach($database as
$row) {
244 $colData[] = $row[$field];
255 public static function DPRODUCT($database,$field,$criteria) {
257 if (is_null($field)) {
265 foreach($database as
$row) {
266 $colData[] = $row[$field];
277 public static function DSTDEV($database,$field,$criteria) {
279 if (is_null($field)) {
287 foreach($database as
$row) {
288 $colData[] = $row[$field];
299 public static function DSTDEVP($database,$field,$criteria) {
301 if (is_null($field)) {
309 foreach($database as
$row) {
310 $colData[] = $row[$field];
321 public static function DSUM($database,$field,$criteria) {
323 if (is_null($field)) {
331 foreach($database as
$row) {
332 $colData[] = $row[$field];
343 public static function DVAR($database,$field,$criteria) {
345 if (is_null($field)) {
353 foreach($database as
$row) {
354 $colData[] = $row[$field];
365 public static function DVARP($database,$field,$criteria) {
367 if (is_null($field)) {
375 foreach($database as
$row) {
376 $colData[] = $row[$field];