From 229da01d9a8cabb14de42d2f8a54b08eb3f0ada4 Mon Sep 17 00:00:00 2001 From: Isuru Palliyaguru Date: Mon, 30 May 2016 12:17:43 +1200 Subject: [PATCH] set data type to string in columns --- Classes/PHPExcel/Worksheet.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php index 483aa0021..94a2a8191 100644 --- a/Classes/PHPExcel/Worksheet.php +++ b/Classes/PHPExcel/Worksheet.php @@ -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) @@ -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