Skip to content

Commit dc80502

Browse files
committed
fix date format
1 parent 2ed9487 commit dc80502

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Maatwebsite/Excel/Excel.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Config;
44
use Maatwebsite\Excel\Readers\HTML_reader;
55
use \PHPExcel_Shared_Date;
6+
use \PHPExcel_Style_NumberFormat;
67

78
/**
89
* Laravel wrapper for PHPEXcel
@@ -804,11 +805,21 @@ private function parseCells()
804805
// If the cell is a date time and we want to parse them
805806
if($this->formatDates !== false && PHPExcel_Shared_Date::isDateTime($this->cell))
806807
{
807-
// Convert excel time to php date object
808-
$value = PHPExcel_Shared_Date::ExcelToPHPObject($this->cell->getCalculatedValue());
809-
810808
// Format the date
811-
$value = $value->format($this->dateFormat);
809+
if ($this->formatDates !== false)
810+
{
811+
$value = PHPExcel_Shared_Date::ExcelToPHPObject($this->cell->getCalculatedValue());
812+
$value = $value->format($this->dateFormat);
813+
}
814+
else {
815+
$value = (string) PHPExcel_Style_NumberFormat::toFormattedString(
816+
$this->cell->getCalculatedValue(),
817+
$this->cell->getWorksheet()->getParent()
818+
->getCellXfByIndex($this->cell->getXfIndex())
819+
->getNumberFormat()
820+
->getFormatCode()
821+
);
822+
}
812823

813824
if($this->useCarbon)
814825
{

0 commit comments

Comments
 (0)