maatwebsite/excel导入日期格式的问题
xuexi 2025-07-18 13:39:40 发表在:PHP 查看数:25

无需重新安装该类,包里面已经带了

use PhpOffice\PhpSpreadsheet\Shared\Date;
 'riqi' =>  Date::excelToDateTimeObject($row['日期'])->format('Y-m-d'),

完整代码

use PhpOffice\PhpSpreadsheet\Shared\Date;

class YourImport implements ToModel 
{
    public function model(array $row)
    {
        return new YourModel([
            'riqi' => Date::excelToDateTimeObject($row[0])->format('Y-m-d'),
        ]);
    }
}
最近访问时间:2025-07-21 09:26:44
知识库:359条鸣谢:TAY  备案号:蜀ICP备2024090044号-2