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 e8320cc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/Service/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,18 @@ 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;
// $cellIterator`s index is based on 1, not 0.
$colIndex = $cellIterator->getCurrentColumnIndex() - 1;
$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 e8320cc

Please sign in to comment.