Skip to content
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.

added function fromArrayExplicit #770

Open
wants to merge 2 commits into
base: 1.8
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Classes/PHPExcel/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down