diff --git a/src/Maatwebsite/Excel/Excel.php b/src/Maatwebsite/Excel/Excel.php index 3acd5dd2b..b9be38ee2 100644 --- a/src/Maatwebsite/Excel/Excel.php +++ b/src/Maatwebsite/Excel/Excel.php @@ -3,6 +3,7 @@ use Config; use Maatwebsite\Excel\Readers\HTML_reader; use \PHPExcel_Shared_Date; +use \PHPExcel_Style_NumberFormat; /** * Laravel wrapper for PHPEXcel @@ -657,22 +658,10 @@ private function parseFile() // Get the sheet count $this->sheetCount = $this->excel->getSheetCount(); - // If we have more than 1 worksheet, seperate them - if($this->sheetCount > 1) - { - - // Parse the rows into seperate worksheets - $parsed[$title] = $this->parseRows(); - - } - else - { - // Parse the rows, but neglect the worksheet title - $parsed = $this->parseRows(); - } + // Parse the rows into seperate worksheets + $parsed[$title] = $this->parseRows(); $i++; - } @@ -715,7 +704,7 @@ private function getLabels() foreach ($this->row->getCellIterator() as $this->cell) { // Set labels - $this->labels[] = str_replace(' ', '-',strtolower($this->cell->getValue())); + $this->labels[] = \Str::slug($this->cell->getValue()); } @@ -795,24 +784,34 @@ private function parseCells() $index = \PHPExcel_Cell::columnIndexFromString($this->cell->getColumn()); // Check how we need to save the parsed array - if($this->firstRowAsLabel !== false) + if($this->firstRowAsLabel !== false and isset($this->labels[$i])) { // Set label index $index = $this->labels[$i]; } // If the cell is a date time and we want to parse them - if($this->formatDates !== false && PHPExcel_Shared_Date::isDateTime($this->cell)) + if ($this->cell->getCalculatedValue() and PHPExcel_Shared_Date::isDateTime($this->cell)) { - // Convert excel time to php date object - $value = PHPExcel_Shared_Date::ExcelToPHPObject($this->cell->getCalculatedValue()); - // Format the date - $value = $value->format($this->dateFormat); + if ($this->formatDates !== false) + { + $value = PHPExcel_Shared_Date::ExcelToPHPObject($this->cell->getCalculatedValue()); + $value = $value->format($this->dateFormat); + } + else { + $value = (string) PHPExcel_Style_NumberFormat::toFormattedString( + $this->cell->getCalculatedValue(), + $this->cell->getWorksheet()->getParent() + ->getCellXfByIndex($this->cell->getXfIndex()) + ->getNumberFormat() + ->getFormatCode() + ); + } - if($this->useCarbon) + if ($this->useCarbon) { - $value = \Carbon::parse($value)->{$this->carbonMethod}(); + $value = \Carbon\Carbon::parse($value)->{$this->carbonMethod}(); } }