34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../../');
35 require(PHPEXCEL_ROOT .
'PHPExcel/Autoloader.php');
69 $fieldNames = array_map(
'strtoupper',array_shift($database));
71 if (is_numeric($field)) {
72 $keys = array_keys($fieldNames);
73 return $keys[$field-1];
75 $key = array_search($field,$fieldNames);
98 private static function __filter($database,$criteria) {
99 $fieldNames = array_shift($database);
100 $criteriaNames = array_shift($criteria);
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] >
'') {
111 $testConditionCount++;
114 if ($testConditionCount > 1) {
115 $testConditions[] =
'OR('.implode(
',',$testCondition).
')';
116 $testConditionsCount++;
117 } elseif($testConditionCount == 1) {
118 $testConditions[] = $testCondition[0];
119 $testConditionsCount++;
123 if ($testConditionsCount > 1) {
124 $testConditionSet =
'AND('.implode(
',',$testConditions).
')';
125 } elseif($testConditionsCount == 1) {
126 $testConditionSet = $testConditions[0];
130 foreach($database as $dataRow => $dataValues) {
132 $testConditionList = $testConditionSet;
133 foreach($criteriaNames as
$key => $criteriaName) {
134 $k = array_search($criteriaName,$fieldNames);
135 if (isset($dataValues[$k])) {
136 $dataValue = $dataValues[$k];
138 $testConditionList = str_replace(
'[:'.$criteriaName.
']',$dataValue,$testConditionList);
145 unset($database[$dataRow]);
180 public static function DAVERAGE($database,$field,$criteria) {
181 $field = self::__fieldExtract($database,$field);
182 if (is_null($field)) {
186 $database = self::__filter($database,$criteria);
189 foreach($database as
$row) {
190 $colData[] = $row[$field];
232 public static function DCOUNT($database,$field,$criteria) {
233 $field = self::__fieldExtract($database,$field);
234 if (is_null($field)) {
239 $database = self::__filter($database,$criteria);
242 foreach($database as
$row) {
243 $colData[] = $row[$field];
281 public static function DCOUNTA($database,$field,$criteria) {
282 $field = self::__fieldExtract($database,$field);
283 if (is_null($field)) {
288 $database = self::__filter($database,$criteria);
291 foreach($database as
$row) {
292 $colData[] = $row[$field];
328 public static function DGET($database,$field,$criteria) {
329 $field = self::__fieldExtract($database,$field);
330 if (is_null($field)) {
335 $database = self::__filter($database,$criteria);
338 foreach($database as
$row) {
339 $colData[] = $row[$field];
343 if (count($colData) > 1) {
379 public static function DMAX($database,$field,$criteria) {
380 $field = self::__fieldExtract($database,$field);
381 if (is_null($field)) {
386 $database = self::__filter($database,$criteria);
389 foreach($database as
$row) {
390 $colData[] = $row[$field];
426 public static function DMIN($database,$field,$criteria) {
427 $field = self::__fieldExtract($database,$field);
428 if (is_null($field)) {
433 $database = self::__filter($database,$criteria);
436 foreach($database as
$row) {
437 $colData[] = $row[$field];
472 public static function DPRODUCT($database,$field,$criteria) {
473 $field = self::__fieldExtract($database,$field);
474 if (is_null($field)) {
479 $database = self::__filter($database,$criteria);
482 foreach($database as
$row) {
483 $colData[] = $row[$field];
519 public static function DSTDEV($database,$field,$criteria) {
520 $field = self::__fieldExtract($database,$field);
521 if (is_null($field)) {
526 $database = self::__filter($database,$criteria);
529 foreach($database as
$row) {
530 $colData[] = $row[$field];
566 public static function DSTDEVP($database,$field,$criteria) {
567 $field = self::__fieldExtract($database,$field);
568 if (is_null($field)) {
573 $database = self::__filter($database,$criteria);
576 foreach($database as
$row) {
577 $colData[] = $row[$field];
612 public static function DSUM($database,$field,$criteria) {
613 $field = self::__fieldExtract($database,$field);
614 if (is_null($field)) {
619 $database = self::__filter($database,$criteria);
622 foreach($database as
$row) {
623 $colData[] = $row[$field];
659 public static function DVAR($database,$field,$criteria) {
660 $field = self::__fieldExtract($database,$field);
661 if (is_null($field)) {
666 $database = self::__filter($database,$criteria);
669 foreach($database as
$row) {
670 $colData[] = $row[$field];
706 public static function DVARP($database,$field,$criteria) {
707 $field = self::__fieldExtract($database,$field);
708 if (is_null($field)) {
713 $database = self::__filter($database,$criteria);
716 foreach($database as
$row) {
717 $colData[] = $row[$field];
static DVARP($database, $field, $criteria)
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
static DAVERAGE($database, $field, $criteria)
static DCOUNT($database, $field, $criteria)
static DCOUNTA($database, $field, $criteria)
static DGET($database, $field, $criteria)
static _wrapResult($value)
Wrap string values in quotes.
static DSUM($database, $field, $criteria)
static DPRODUCT($database, $field, $criteria)
static DSTDEVP($database, $field, $criteria)
static _ifCondition($condition)
static DSTDEV($database, $field, $criteria)
Create styles array
The data for the language used.
static DVAR($database, $field, $criteria)
static DMIN($database, $field, $criteria)
static getInstance(PHPExcel $workbook=NULL)
Get an instance of this class.
static DMAX($database, $field, $criteria)
static __fieldExtract($database, $field)
__fieldExtract
static __filter($database, $criteria)
__filter
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'