From 650061f354d2a396d13868df5945881eeb852682 Mon Sep 17 00:00:00 2001 From: Adrian C Date: Sat, 19 Dec 2015 01:37:32 +0100 Subject: [PATCH 1/2] added function fromArrayExplicit --- Classes/PHPExcel/Worksheet.php | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php index 51470c3e8..dd41ba4a1 100644 --- a/Classes/PHPExcel/Worksheet.php +++ b/Classes/PHPExcel/Worksheet.php @@ -2441,6 +2441,49 @@ public function fromArray($source = null, $nullValue = null, $startCell = 'A1', return $this; } + /** + * Fill worksheet from values in array with specified cell data type + * ex: + * $source = array( + * array( + * array('value1', PHPExcel_Cell_DataType::TYPE_STRING), + * array('value2', PHPExcel_Cell_DataType::TYPE_FORMULA), + * ), + * array( + * array('value3', PHPExcel_Cell_DataType::TYPE_STRING), + * array('value4', PHPExcel_Cell_DataType::TYPE_NUMBER), + * ) + * ); + * + * @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 + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function fromArrayExplicit($source = null, $nullValue = null, $startCell = 'A1') + { + if (is_array($source)) { + // start coordinate + list ($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($startCell); + + // Loop through $source + foreach ($source as $rowData) { + $currentColumn = $startColumn; + foreach ($rowData as $cellValue) { + if ($cellValue != $nullValue) { + $this->getCell($currentColumn . $startRow)->setValueExplicit($cellValue[0], $cellValue[1]); // value, dataType + } + ++$currentColumn; + } + ++$startRow; + } + } else { + throw new PHPExcel_Exception("Parameter \$source should be an array."); + } + return $this; + } + /** * Create array from a range of cells * From 5aeec2323994aa11e2fd7df6b1009a69eb12eb64 Mon Sep 17 00:00:00 2001 From: Adrian C Date: Sat, 19 Dec 2015 01:42:14 +0100 Subject: [PATCH 2/2] added function fromArrayExplicit --- Classes/PHPExcel/Worksheet.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php index dd41ba4a1..ac4a9bc67 100644 --- a/Classes/PHPExcel/Worksheet.php +++ b/Classes/PHPExcel/Worksheet.php @@ -2443,17 +2443,6 @@ public function fromArray($source = null, $nullValue = null, $startCell = 'A1', /** * Fill worksheet from values in array with specified cell data type - * ex: - * $source = array( - * array( - * array('value1', PHPExcel_Cell_DataType::TYPE_STRING), - * array('value2', PHPExcel_Cell_DataType::TYPE_FORMULA), - * ), - * array( - * array('value3', PHPExcel_Cell_DataType::TYPE_STRING), - * array('value4', PHPExcel_Cell_DataType::TYPE_NUMBER), - * ) - * ); * * @param array $source Source array * @param mixed $nullValue Value in source array that stands for blank cell