diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php index 51470c3e8..ac4a9bc67 100644 --- a/Classes/PHPExcel/Worksheet.php +++ b/Classes/PHPExcel/Worksheet.php @@ -2441,6 +2441,38 @@ public function fromArray($source = null, $nullValue = null, $startCell = 'A1', return $this; } + /** + * Fill worksheet from values in array with specified cell data type + * + * @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 *