Skip to content

Commit

Permalink
fix(Import): use correct int index of literal one
Browse files Browse the repository at this point in the history
… and get date value with fault tolerance

Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Nov 15, 2024
1 parent 9e04d7c commit b154e9e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/Service/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b154e9e

Please sign in to comment.