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

set data type to string in columns #909

Open
wants to merge 1 commit 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
8 changes: 7 additions & 1 deletion Classes/PHPExcel/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2409,10 +2409,11 @@ public function setRightToLeft($value = false)
* @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
* @param array $setColumnsToText array of the columns we need to set as text (eg A,B,C)
* @throws PHPExcel_Exception
* @return PHPExcel_Worksheet
*/
public function fromArray($source = null, $nullValue = null, $startCell = 'A1', $strictNullComparison = false)
public function fromArray($source = null, $nullValue = null, $startCell = 'A1', $strictNullComparison = false, $setColumnsToText = array())
{
if (is_array($source)) {
// Convert a 1-D array to 2-D (for ease of looping)
Expand All @@ -2432,6 +2433,11 @@ public function fromArray($source = null, $nullValue = null, $startCell = 'A1',
// Set cell value
$this->getCell($currentColumn . $startRow)->setValue($cellValue);
}
} else if (!empty($setColumnsToText) && (in_array($currentColumn,$setColumnsToText))) {
if ($cellValue != $nullValue) {
// Set cell value explicitly to string to avoid string '8524510E4' converting to '85245100000'
$this->getCell($currentColumn . $startRow)->setValueExplicit($cellValue,PHPExcel_Cell_DataType::TYPE_STRING);
}
} else {
if ($cellValue != $nullValue) {
// Set cell value
Expand Down