Feature: Added strictNullComparison argument to the worksheet fromArray() method

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@64270 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker
2010-11-24 15:28:15 +00:00
parent b25ced63cc
commit 6c9a41879b
2 changed files with 18 additions and 8 deletions
+17 -8
View File
@@ -2082,7 +2082,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
/**
* Set right-to-left
*
* @param boolean $value Right-to-left true/false
* @param boolean $value Right-to-left true/false
* @return PHPExcel_Worksheet
*/
public function setRightToLeft($value = false) {
@@ -2093,23 +2093,32 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
/**
* Fill worksheet from values in array
*
* @param array $source Source array
* @param mixed $nullValue Value in source array that stands for blank cell
* @param array $source Source array
* @param mixed $nullValue Value in source array that stands for blank cell
* @param string $startCell Insert array starting from this cell address as the top left coordinate
* @param boolean $strictNullComparison Apply strict comparison when testing for null values in the array
* @throws Exception
* @return PHPExcel_Worksheet
*/
public function fromArray($source = null, $nullValue = null, $pCell = 'A1') {
public function fromArray($source = null, $nullValue = null, $startCell = 'A1', $strictNullComparison = false) {
if (is_array($source)) {
// start coordinate
list ($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($pCell);
list ($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($startCell);
// Loop through $source
foreach ($source as $rowData) {
$currentColumn = $startColumn;
foreach($rowData as $cellValue) {
if ($cellValue != $nullValue) {
// Set cell value
$this->getCell($currentColumn . $startRow)->setValue($cellValue);
if ($strictNullComparison) {
if ($cellValue !== $nullValue) {
// Set cell value
$this->getCell($currentColumn . $startRow)->setValue($cellValue);
}
} else {
if ($cellValue != $nullValue) {
// Set cell value
$this->getCell($currentColumn . $startRow)->setValue($cellValue);
}
}
++$currentColumn;
}