From b154e9ec9073eae80fdaaf29bddb4731a9256c99 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 15 Nov 2024 16:42:03 +0100 Subject: [PATCH] fix(Import): use correct int index of literal one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … and get date value with fault tolerance Signed-off-by: Arthur Schiwon --- lib/Service/ImportService.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Service/ImportService.php b/lib/Service/ImportService.php index 78aa70b4b..2d34a154b 100644 --- a/lib/Service/ImportService.php +++ b/lib/Service/ImportService.php @@ -154,13 +154,17 @@ private function getPreviewData(Worksheet $worksheet): array { $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(false); - foreach ($cellIterator as $cellIndex => $cell) { + foreach ($cellIterator as $cell) { $value = $cell->getValue(); - $colIndex = (int) $cellIndex; + $colIndex = $cellIterator->getCurrentColumnIndex(); $column = $this->columns[$colIndex]; if (($column && $column->getType() === 'datetime') || (is_array($columns[$colIndex]) && $columns[$colIndex]['type'] === 'datetime')) { - $value = Date::excelToDateTimeObject($value)->format('Y-m-d H:i'); + try { + $value = Date::excelToDateTimeObject($value)->format('Y-m-d H:i'); + } catch (\TypeError) { + $value = (new \DateTimeImmutable($value))->format('Y-m-d H:i'); + } } elseif (($column && $column->getType() === 'number' && $column->getNumberSuffix() === '%') || (is_array($columns[$colIndex]) && $columns[$colIndex]['type'] === 'number' && $columns[$colIndex]['numberSuffix'] === '%')) { $value = $value * 100;