summaryrefslogtreecommitdiffstats
path: root/admin/survey/excel/PHPExcel/Calculation/Database.php
blob: 8159896d5a4140a7592c46546249dab4845fb4d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
<?php
/**
 * PHPExcel
 *
 * Copyright (c) 2006 - 2012 PHPExcel
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * @category	PHPExcel
 * @package		PHPExcel_Calculation
 * @copyright	Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
 * @license		http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL
 * @version		1.7.8, 2012-10-12
 */


/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
	/**
	 * @ignore
	 */
	define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
	require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}


/**
 * PHPExcel_Calculation_Database
 *
 * @category	PHPExcel
 * @package		PHPExcel_Calculation
 * @copyright	Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
 */
class PHPExcel_Calculation_Database {


	/**
	 * __fieldExtract
	 *
	 * Extracts the column ID to use for the data field.
	 *
	 * @access	private
	 * @param	mixed[]		$database		The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	mixed		$field			Indicates which column is used in the function. Enter the
	 *										column label enclosed between double quotation marks, such as
	 *										"Age" or "Yield," or a number (without quotation marks) that
	 *										represents the position of the column within the list: 1 for
	 *										the first column, 2 for the second column, and so on.
	 * @return	string|NULL
	 *
	 */
	private static function __fieldExtract($database,$field) {
		$field = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($field));
		$fieldNames = array_map('strtoupper',array_shift($database));

		if (is_numeric($field)) {
			$keys = array_keys($fieldNames);
			return $keys[$field-1];
		}
		$key = array_search($field,$fieldNames);
		return ($key) ? $key : NULL;
	}

	/**
	 * __filter
	 *
	 * Parses the selection criteria, extracts the database rows that match those criteria, and
	 * returns that subset of rows.
	 *
	 * @access	private
	 * @param	mixed[]		$database		The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	mixed[]		$criteria		The range of cells that contains the conditions you specify.
	 *										You can use any range for the criteria argument, as long as it
	 *										includes at least one column label and at least one cell below
	 *										the column label in which you specify a condition for the
	 *										column.
	 * @return	array of mixed
	 *
	 */
	private static function __filter($database,$criteria) {
		$fieldNames = array_shift($database);
		$criteriaNames = array_shift($criteria);

		//	Convert the criteria into a set of AND/OR conditions with [:placeholders]
		$testConditions = $testValues = array();
		$testConditionsCount = 0;
		foreach($criteriaNames as $key => $criteriaName) {
			$testCondition = array();
			$testConditionCount = 0;
			foreach($criteria as $row => $criterion) {
				if ($criterion[$key] > '') {
					$testCondition[] = '[:'.$criteriaName.']'.PHPExcel_Calculation_Functions::_ifCondition($criterion[$key]);
					$testConditionCount++;
				}
			}
			if ($testConditionCount > 1) {
				$testConditions[] = 'OR('.implode(',',$testCondition).')';
				$testConditionsCount++;
			} elseif($testConditionCount == 1) {
				$testConditions[] = $testCondition[0];
				$testConditionsCount++;
			}
		}

		if ($testConditionsCount > 1) {
			$testConditionSet = 'AND('.implode(',',$testConditions).')';
		} elseif($testConditionsCount == 1) {
			$testConditionSet = $testConditions[0];
		}

		//	Loop through each row of the database
		foreach($database as $dataRow => $dataValues) {
			//	Substitute actual values from the database row for our [:placeholders]
			$testConditionList = $testConditionSet;
			foreach($criteriaNames as $key => $criteriaName) {
				$k = array_search($criteriaName,$fieldNames);
				if (isset($dataValues[$k])) {
					$dataValue = $dataValues[$k];
					$dataValue = (is_string($dataValue)) ? PHPExcel_Calculation::_wrapResult(strtoupper($dataValue)) : $dataValue;
					$testConditionList = str_replace('[:'.$criteriaName.']',$dataValue,$testConditionList);
				}
			}
			//	evaluate the criteria against the row data
			$result = PHPExcel_Calculation::getInstance()->_calculateFormulaValue('='.$testConditionList);
			//	If the row failed to meet the criteria, remove it from the database
			if (!$result) {
				unset($database[$dataRow]);
			}
		}

		return $database;
	}


	/**
	 * DAVERAGE
	 *
	 * Averages the values in a column of a list or database that match conditions you specify.
	 *
	 * Excel Function:
	 *		DAVERAGE(database,field,criteria)
	 *
	 * @access	public
	 * @category Database Functions
	 * @param	mixed[]			$database	The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	string|integer	$field		Indicates which column is used in the function. Enter the
	 *										column label enclosed between double quotation marks, such as
	 *										"Age" or "Yield," or a number (without quotation marks) that
	 *										represents the position of the column within the list: 1 for
	 *										the first column, 2 for the second column, and so on.
	 * @param	mixed[]			$criteria	The range of cells that contains the conditions you specify.
	 *										You can use any range for the criteria argument, as long as it
	 *										includes at least one column label and at least one cell below
	 *										the column label in which you specify a condition for the
	 *										column.
	 * @return	float
	 *
	 */
	public static function DAVERAGE($database,$field,$criteria) {
		$field = self::__fieldExtract($database,$field);
		if (is_null($field)) {
			return NULL;
		}
		//	reduce the database to a set of rows that match all the criteria
		$database = self::__filter($database,$criteria);
		//	extract an array of values for the requested column
		$colData = array();
		foreach($database as $row) {
			$colData[] = $row[$field];
		}

		// Return
		return PHPExcel_Calculation_Statistical::AVERAGE($colData);
	}	//	function DAVERAGE()


	/**
	 * DCOUNT
	 *
	 * Counts the cells that contain numbers in a column of a list or database that match conditions
	 * that you specify.
	 *
	 * Excel Function:
	 *		DCOUNT(database,[field],criteria)
	 *
	 * Excel Function:
	 *		DAVERAGE(database,field,criteria)
	 *
	 * @access	public
	 * @category Database Functions
	 * @param	mixed[]			$database	The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	string|integer	$field		Indicates which column is used in the function. Enter the
	 *										column label enclosed between double quotation marks, such as
	 *										"Age" or "Yield," or a number (without quotation marks) that
	 *										represents the position of the column within the list: 1 for
	 *										the first column, 2 for the second column, and so on.
	 * @param	mixed[]			$criteria	The range of cells that contains the conditions you specify.
	 *										You can use any range for the criteria argument, as long as it
	 *										includes at least one column label and at least one cell below
	 *										the column label in which you specify a condition for the
	 *										column.
	 * @return	integer
	 *
	 * @TODO	The field argument is optional. If field is omitted, DCOUNT counts all records in the
	 *			database that match the criteria.
	 *
	 */
	public static function DCOUNT($database,$field,$criteria) {
		$field = self::__fieldExtract($database,$field);
		if (is_null($field)) {
			return NULL;
		}

		//	reduce the database to a set of rows that match all the criteria
		$database = self::__filter($database,$criteria);
		//	extract an array of values for the requested column
		$colData = array();
		foreach($database as $row) {
			$colData[] = $row[$field];
		}

		// Return
		return PHPExcel_Calculation_Statistical::COUNT($colData);
	}	//	function DCOUNT()


	/**
	 * DCOUNTA
	 *
	 * Counts the nonblank cells in a column of a list or database that match conditions that you specify.
	 *
	 * Excel Function:
	 *		DCOUNTA(database,[field],criteria)
	 *
	 * @access	public
	 * @category Database Functions
	 * @param	mixed[]			$database	The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	string|integer	$field		Indicates which column is used in the function. Enter the
	 *										column label enclosed between double quotation marks, such as
	 *										"Age" or "Yield," or a number (without quotation marks) that
	 *										represents the position of the column within the list: 1 for
	 *										the first column, 2 for the second column, and so on.
	 * @param	mixed[]			$criteria	The range of cells that contains the conditions you specify.
	 *										You can use any range for the criteria argument, as long as it
	 *										includes at least one column label and at least one cell below
	 *										the column label in which you specify a condition for the
	 *										column.
	 * @return	integer
	 *
	 * @TODO	The field argument is optional. If field is omitted, DCOUNTA counts all records in the
	 *			database that match the criteria.
	 *
	 */
	public static function DCOUNTA($database,$field,$criteria) {
		$field = self::__fieldExtract($database,$field);
		if (is_null($field)) {
			return NULL;
		}

		//	reduce the database to a set of rows that match all the criteria
		$database = self::__filter($database,$criteria);
		//	extract an array of values for the requested column
		$colData = array();
		foreach($database as $row) {
			$colData[] = $row[$field];
		}

		// Return
		return PHPExcel_Calculation_Statistical::COUNTA($colData);
	}	//	function DCOUNTA()


	/**
	 * DGET
	 *
	 * Extracts a single value from a column of a list or database that matches conditions that you
	 * specify.
	 *
	 * Excel Function:
	 *		DGET(database,field,criteria)
	 *
	 * @access	public
	 * @category Database Functions
	 * @param	mixed[]			$database	The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	string|integer	$field		Indicates which column is used in the function. Enter the
	 *										column label enclosed between double quotation marks, such as
	 *										"Age" or "Yield," or a number (without quotation marks) that
	 *										represents the position of the column within the list: 1 for
	 *										the first column, 2 for the second column, and so on.
	 * @param	mixed[]			$criteria	The range of cells that contains the conditions you specify.
	 *										You can use any range for the criteria argument, as long as it
	 *										includes at least one column label and at least one cell below
	 *										the column label in which you specify a condition for the
	 *										column.
	 * @return	mixed
	 *
	 */
	public static function DGET($database,$field,$criteria) {
		$field = self::__fieldExtract($database,$field);
		if (is_null($field)) {
			return NULL;
		}

		//	reduce the database to a set of rows that match all the criteria
		$database = self::__filter($database,$criteria);
		//	extract an array of values for the requested column
		$colData = array();
		foreach($database as $row) {
			$colData[] = $row[$field];
		}

		// Return
		if (count($colData) > 1) {
			return PHPExcel_Calculation_Functions::NaN();
		}

		return $colData[0];
	}	//	function DGET()


	/**
	 * DMAX
	 *
	 * Returns the largest number in a column of a list or database that matches conditions you that
	 * specify.
	 *
	 * Excel Function:
	 *		DMAX(database,field,criteria)
	 *
	 * @access	public
	 * @category Database Functions
	 * @param	mixed[]			$database	The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	string|integer	$field		Indicates which column is used in the function. Enter the
	 *										column label enclosed between double quotation marks, such as
	 *										"Age" or "Yield," or a number (without quotation marks) that
	 *										represents the position of the column within the list: 1 for
	 *										the first column, 2 for the second column, and so on.
	 * @param	mixed[]			$criteria	The range of cells that contains the conditions you specify.
	 *										You can use any range for the criteria argument, as long as it
	 *										includes at least one column label and at least one cell below
	 *										the column label in which you specify a condition for the
	 *										column.
	 * @return	float
	 *
	 */
	public static function DMAX($database,$field,$criteria) {
		$field = self::__fieldExtract($database,$field);
		if (is_null($field)) {
			return NULL;
		}

		//	reduce the database to a set of rows that match all the criteria
		$database = self::__filter($database,$criteria);
		//	extract an array of values for the requested column
		$colData = array();
		foreach($database as $row) {
			$colData[] = $row[$field];
		}

		// Return
		return PHPExcel_Calculation_Statistical::MAX($colData);
	}	//	function DMAX()


	/**
	 * DMIN
	 *
	 * Returns the smallest number in a column of a list or database that matches conditions you that
	 * specify.
	 *
	 * Excel Function:
	 *		DMIN(database,field,criteria)
	 *
	 * @access	public
	 * @category Database Functions
	 * @param	mixed[]			$database	The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	string|integer	$field		Indicates which column is used in the function. Enter the
	 *										column label enclosed between double quotation marks, such as
	 *										"Age" or "Yield," or a number (without quotation marks) that
	 *										represents the position of the column within the list: 1 for
	 *										the first column, 2 for the second column, and so on.
	 * @param	mixed[]			$criteria	The range of cells that contains the conditions you specify.
	 *										You can use any range for the criteria argument, as long as it
	 *										includes at least one column label and at least one cell below
	 *										the column label in which you specify a condition for the
	 *										column.
	 * @return	float
	 *
	 */
	public static function DMIN($database,$field,$criteria) {
		$field = self::__fieldExtract($database,$field);
		if (is_null($field)) {
			return NULL;
		}

		//	reduce the database to a set of rows that match all the criteria
		$database = self::__filter($database,$criteria);
		//	extract an array of values for the requested column
		$colData = array();
		foreach($database as $row) {
			$colData[] = $row[$field];
		}

		// Return
		return PHPExcel_Calculation_Statistical::MIN($colData);
	}	//	function DMIN()


	/**
	 * DPRODUCT
	 *
	 * Multiplies the values in a column of a list or database that match conditions that you specify.
	 *
	 * Excel Function:
	 *		DPRODUCT(database,field,criteria)
	 *
	 * @access	public
	 * @category Database Functions
	 * @param	mixed[]			$database	The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	string|integer	$field		Indicates which column is used in the function. Enter the
	 *										column label enclosed between double quotation marks, such as
	 *										"Age" or "Yield," or a number (without quotation marks) that
	 *										represents the position of the column within the list: 1 for
	 *										the first column, 2 for the second column, and so on.
	 * @param	mixed[]			$criteria	The range of cells that contains the conditions you specify.
	 *										You can use any range for the criteria argument, as long as it
	 *										includes at least one column label and at least one cell below
	 *										the column label in which you specify a condition for the
	 *										column.
	 * @return	float
	 *
	 */
	public static function DPRODUCT($database,$field,$criteria) {
		$field = self::__fieldExtract($database,$field);
		if (is_null($field)) {
			return NULL;
		}

		//	reduce the database to a set of rows that match all the criteria
		$database = self::__filter($database,$criteria);
		//	extract an array of values for the requested column
		$colData = array();
		foreach($database as $row) {
			$colData[] = $row[$field];
		}

		// Return
		return PHPExcel_Calculation_MathTrig::PRODUCT($colData);
	}	//	function DPRODUCT()


	/**
	 * DSTDEV
	 *
	 * Estimates the standard deviation of a population based on a sample by using the numbers in a
	 * column of a list or database that match conditions that you specify.
	 *
	 * Excel Function:
	 *		DSTDEV(database,field,criteria)
	 *
	 * @access	public
	 * @category Database Functions
	 * @param	mixed[]			$database	The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	string|integer	$field		Indicates which column is used in the function. Enter the
	 *										column label enclosed between double quotation marks, such as
	 *										"Age" or "Yield," or a number (without quotation marks) that
	 *										represents the position of the column within the list: 1 for
	 *										the first column, 2 for the second column, and so on.
	 * @param	mixed[]			$criteria	The range of cells that contains the conditions you specify.
	 *										You can use any range for the criteria argument, as long as it
	 *										includes at least one column label and at least one cell below
	 *										the column label in which you specify a condition for the
	 *										column.
	 * @return	float
	 *
	 */
	public static function DSTDEV($database,$field,$criteria) {
		$field = self::__fieldExtract($database,$field);
		if (is_null($field)) {
			return NULL;
		}

		//	reduce the database to a set of rows that match all the criteria
		$database = self::__filter($database,$criteria);
		//	extract an array of values for the requested column
		$colData = array();
		foreach($database as $row) {
			$colData[] = $row[$field];
		}

		// Return
		return PHPExcel_Calculation_Statistical::STDEV($colData);
	}	//	function DSTDEV()


	/**
	 * DSTDEVP
	 *
	 * Calculates the standard deviation of a population based on the entire population by using the
	 * numbers in a column of a list or database that match conditions that you specify.
	 *
	 * Excel Function:
	 *		DSTDEVP(database,field,criteria)
	 *
	 * @access	public
	 * @category Database Functions
	 * @param	mixed[]			$database	The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	string|integer	$field		Indicates which column is used in the function. Enter the
	 *										column label enclosed between double quotation marks, such as
	 *										"Age" or "Yield," or a number (without quotation marks) that
	 *										represents the position of the column within the list: 1 for
	 *										the first column, 2 for the second column, and so on.
	 * @param	mixed[]			$criteria	The range of cells that contains the conditions you specify.
	 *										You can use any range for the criteria argument, as long as it
	 *										includes at least one column label and at least one cell below
	 *										the column label in which you specify a condition for the
	 *										column.
	 * @return	float
	 *
	 */
	public static function DSTDEVP($database,$field,$criteria) {
		$field = self::__fieldExtract($database,$field);
		if (is_null($field)) {
			return NULL;
		}

		//	reduce the database to a set of rows that match all the criteria
		$database = self::__filter($database,$criteria);
		//	extract an array of values for the requested column
		$colData = array();
		foreach($database as $row) {
			$colData[] = $row[$field];
		}

		// Return
		return PHPExcel_Calculation_Statistical::STDEVP($colData);
	}	//	function DSTDEVP()


	/**
	 * DSUM
	 *
	 * Adds the numbers in a column of a list or database that match conditions that you specify.
	 *
	 * Excel Function:
	 *		DSUM(database,field,criteria)
	 *
	 * @access	public
	 * @category Database Functions
	 * @param	mixed[]			$database	The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	string|integer	$field		Indicates which column is used in the function. Enter the
	 *										column label enclosed between double quotation marks, such as
	 *										"Age" or "Yield," or a number (without quotation marks) that
	 *										represents the position of the column within the list: 1 for
	 *										the first column, 2 for the second column, and so on.
	 * @param	mixed[]			$criteria	The range of cells that contains the conditions you specify.
	 *										You can use any range for the criteria argument, as long as it
	 *										includes at least one column label and at least one cell below
	 *										the column label in which you specify a condition for the
	 *										column.
	 * @return	float
	 *
	 */
	public static function DSUM($database,$field,$criteria) {
		$field = self::__fieldExtract($database,$field);
		if (is_null($field)) {
			return NULL;
		}

		//	reduce the database to a set of rows that match all the criteria
		$database = self::__filter($database,$criteria);
		//	extract an array of values for the requested column
		$colData = array();
		foreach($database as $row) {
			$colData[] = $row[$field];
		}

		// Return
		return PHPExcel_Calculation_MathTrig::SUM($colData);
	}	//	function DSUM()


	/**
	 * DVAR
	 *
	 * Estimates the variance of a population based on a sample by using the numbers in a column
	 * of a list or database that match conditions that you specify.
	 *
	 * Excel Function:
	 *		DVAR(database,field,criteria)
	 *
	 * @access	public
	 * @category Database Functions
	 * @param	mixed[]			$database	The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	string|integer	$field		Indicates which column is used in the function. Enter the
	 *										column label enclosed between double quotation marks, such as
	 *										"Age" or "Yield," or a number (without quotation marks) that
	 *										represents the position of the column within the list: 1 for
	 *										the first column, 2 for the second column, and so on.
	 * @param	mixed[]			$criteria	The range of cells that contains the conditions you specify.
	 *										You can use any range for the criteria argument, as long as it
	 *										includes at least one column label and at least one cell below
	 *										the column label in which you specify a condition for the
	 *										column.
	 * @return	float
	 *
	 */
	public static function DVAR($database,$field,$criteria) {
		$field = self::__fieldExtract($database,$field);
		if (is_null($field)) {
			return NULL;
		}

		//	reduce the database to a set of rows that match all the criteria
		$database = self::__filter($database,$criteria);
		//	extract an array of values for the requested column
		$colData = array();
		foreach($database as $row) {
			$colData[] = $row[$field];
		}

		// Return
		return PHPExcel_Calculation_Statistical::VARFunc($colData);
	}	//	function DVAR()


	/**
	 * DVARP
	 *
	 * Calculates the variance of a population based on the entire population by using the numbers
	 * in a column of a list or database that match conditions that you specify.
	 *
	 * Excel Function:
	 *		DVARP(database,field,criteria)
	 *
	 * @access	public
	 * @category Database Functions
	 * @param	mixed[]			$database	The range of cells that makes up the list or database.
	 *										A database is a list of related data in which rows of related
	 *										information are records, and columns of data are fields. The
	 *										first row of the list contains labels for each column.
	 * @param	string|integer	$field		Indicates which column is used in the function. Enter the
	 *										column label enclosed between double quotation marks, such as
	 *										"Age" or "Yield," or a number (without quotation marks) that
	 *										represents the position of the column within the list: 1 for
	 *										the first column, 2 for the second column, and so on.
	 * @param	mixed[]			$criteria	The range of cells that contains the conditions you specify.
	 *										You can use any range for the criteria argument, as long as it
	 *										includes at least one column label and at least one cell below
	 *										the column label in which you specify a condition for the
	 *										column.
	 * @return	float
	 *
	 */
	public static function DVARP($database,$field,$criteria) {
		$field = self::__fieldExtract($database,$field);
		if (is_null($field)) {
			return NULL;
		}

		//	reduce the database to a set of rows that match all the criteria
		$database = self::__filter($database,$criteria);
		//	extract an array of values for the requested column
		$colData = array();
		foreach($database as $row) {
			$colData[] = $row[$field];
		}

		// Return
		return PHPExcel_Calculation_Statistical::VARP($colData);
	}	//	function DVARP()


}	//	class PHPExcel_Calculation_Database