diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index 8702997ecfb..0bf5e587d4c 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -30,6 +30,7 @@ use PhpOffice\PhpSpreadsheet\Reader\Xlsx; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\Alignment; +use PhpOffice\PhpSpreadsheet\Shared\Date; require_once DOL_DOCUMENT_ROOT . '/core/modules/import/modules_import.php'; @@ -302,22 +303,34 @@ class ImportXlsx extends ModeleImports public function import_read_record() { // phpcs:enable - global $conf; - $rowcount = $this->workbook->getActiveSheet()->getHighestDataRow(); if ($this->record > $rowcount) { return false; } $array = array(); + $xlsx = new Xlsx(); $info = $xlsx->listWorksheetinfo($this->file); $countcolumns = $info[0]['totalColumns']; + for ($col = 1; $col <= $countcolumns; $col++) { - $val = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, $this->record)->getValue(); + $tmpcell = $this->workbook->getActiveSheet()->getCellByColumnAndRow($col, $this->record); + + $val = $tmpcell->getValue(); + + if (Date::isDateTime($tmpcell)) { + // For date field, we use the standard date format string. + $dateValue = Date::excelToDateTimeObject($val); + $val = $dateValue->format('Y-m-d H:i:s'); + } + $array[$col]['val'] = $val; $array[$col]['type'] = (dol_strlen($val) ? 1 : -1); // If empty we consider it null } $this->record++; + + unset($xlsx); + return $array; }