|
3 | 3 | use Config; |
4 | 4 | use Maatwebsite\Excel\Readers\HTML_reader; |
5 | 5 | use \PHPExcel_Shared_Date; |
| 6 | +use \PHPExcel_Style_NumberFormat; |
6 | 7 |
|
7 | 8 | /** |
8 | 9 | * Laravel wrapper for PHPEXcel |
@@ -813,19 +814,40 @@ private function parseCells() |
813 | 814 | $index = $this->labels[$i]; |
814 | 815 | } |
815 | 816 |
|
816 | | - // If the cell is a date time and we want to parse them |
817 | | - if($this->formatDates !== false && PHPExcel_Shared_Date::isDateTime($this->cell)) |
| 817 | + // If the cell is a date time |
| 818 | + if(PHPExcel_Shared_Date::isDateTime($this->cell)) |
818 | 819 | { |
819 | | - // Convert excel time to php date object |
820 | | - $value = PHPExcel_Shared_Date::ExcelToPHPObject($this->cell->getCalculatedValue()); |
821 | 820 |
|
822 | | - // Format the date |
823 | | - $value = $value->format($this->dateFormat); |
| 821 | + // Check if we want to parse the dates |
| 822 | + if ($this->formatDates !== false) |
| 823 | + { |
| 824 | + |
| 825 | + // Convert excel time to php date object |
| 826 | + $value = PHPExcel_Shared_Date::ExcelToPHPObject($this->cell->getCalculatedValue()); |
| 827 | + |
| 828 | + // Format the date |
| 829 | + $value = $value->format($this->dateFormat); |
| 830 | + |
| 831 | + // Use carbon to parse the time |
| 832 | + if($this->useCarbon) |
| 833 | + { |
| 834 | + $value = \Carbon::parse($value)->{$this->carbonMethod}(); |
| 835 | + } |
824 | 836 |
|
825 | | - if($this->useCarbon) |
| 837 | + } |
| 838 | + else |
826 | 839 | { |
827 | | - $value = \Carbon::parse($value)->{$this->carbonMethod}(); |
| 840 | + // Format the date to a formatted string |
| 841 | + $value = (string) PHPExcel_Style_NumberFormat::toFormattedString( |
| 842 | + $this->cell->getCalculatedValue(), |
| 843 | + $this->cell->getWorksheet()->getParent() |
| 844 | + ->getCellXfByIndex($this->cell->getXfIndex()) |
| 845 | + ->getNumberFormat() |
| 846 | + ->getFormatCode() |
| 847 | + ); |
828 | 848 | } |
| 849 | + |
| 850 | + |
829 | 851 | } |
830 | 852 |
|
831 | 853 | // Check if we want calculated values or not |
|
0 commit comments