From 6c9a41879b236e4143208e67b0e37debb37e0ec6 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Wed, 24 Nov 2010 15:28:15 +0000 Subject: [PATCH] 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 --- Classes/PHPExcel/Worksheet.php | 25 +++++++++++++++++-------- changelog.txt | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php index 1f998e1..8840c68 100644 --- a/Classes/PHPExcel/Worksheet.php +++ b/Classes/PHPExcel/Worksheet.php @@ -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; } diff --git a/changelog.txt b/changelog.txt index 384ce70..0894690 100644 --- a/changelog.txt +++ b/changelog.txt @@ -34,6 +34,7 @@ Fixed in SVN: - Feature: (MBaker) Configure PDF Writer margins based on Excel Worksheet Margin Settings value - Feature: (MBaker) Added Contiguous flag for the CSV Reader, when working with Read Filters - Feature: (MBaker) Added getFormattedValue() method for cell object +- Feature: (MBaker) Added strictNullComparison argument to the worksheet fromArray() method - Bugfix: (MB) Work item 14143 - NA() doesn't propagate in matrix calc - quick fix in JAMA/Matrix.php - Bugfix: (Progi1984) Work item 7895 - Excel5 : Formula : String constant containing double quotation mark - Bugfix: (Progi1984) Work item 7895 - Excel5 : Formula : Percent