cqp 7 mesiacov pred
rodič
commit
e66d21ca29
1 zmenil súbory, kde vykonal 14 pridanie a 3 odobranie
  1. 14 3
      app/Service/ImportService.php

+ 14 - 3
app/Service/ImportService.php

@@ -21,6 +21,7 @@ use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Storage;
 use Maatwebsite\Excel\Facades\Excel;
 use PhpOffice\PhpSpreadsheet\IOFactory;
+use PhpOffice\PhpSpreadsheet\Shared\Date;
 
 class ImportService extends Service
 {
@@ -275,9 +276,19 @@ class ImportService extends Service
                     $rowData = [];
 
                     foreach ($cellIterator as $cell) {
-                        $cellData = $cell->getFormattedValue();
-                        if(! empty($cellData)) $cellData = $this->convertToYMD($cellData);
-                        $rowData[] = $cellData;
+                        // 判断单元格是否为日期
+                        if (Date::isDateTime($cell)) {
+                            // 将日期转换为 Y-m-d 格式
+                            $formattedDate = Date::excelToDateTimeObject($cell->getValue())->format('Y-m-d');
+                            $rowData[] = $formattedDate;
+                        } else {
+                            // 获取单元格的格式化值
+                            $rowData[] = $cell->getFormattedValue();
+                        }
+
+//                        $cellData = $cell->getFormattedValue();
+//                        if(! empty($cellData)) $cellData = $this->convertToYMD($cellData);
+//                        $rowData[] = $cellData;
                     }
 
                     $sheetData[] = $rowData;