我正在使用Laravel Excel将地址列表管理到应用程序中,但出现以下问题:
当我导入联系人时,Laravel Excel将我的德语邮政编码投给了Date对象:
我得到这个结果:
[
"salutation" => "Sehr geehrte Frau Alberg"
"title" => "Frau"
"firstname" => "Rita"
"lastname" => "Alberg"
"street" => "Str."
"zip" => Carbon @-1615770000 {
date: 1918-10-20 00:00:00.0 Europe/Berlin (+01:00)
}
"city" => "Coswig / Anhalt OT. Stackelitz"
"country" => "Deutschland"
"birthday" => Carbon @13561200 {
date: 1970-06-07 00:00:00.0 Europe/Berlin (+01:00)
}
]
我通过运行函数解决了这个问题,但是现在,zip字段被强制转换为float:
$path = $request->file('csv')->getRealPath();
$results = Excel::load($path, function($reader) {})
->setDateColumns(['birthday'])
->formatDates(true, 'Y-m-d')
->ignoreEmpty()
->get();
然后我得到了这个结果:
[
"salutation" => "Sehr geehrte Frau Alberg"
"title" => "Frau"
"firstname" => "Rita"
"lastname" => "Alberg"
"street" => "Str."
"zip" => 6868.0
"city" => "Coswig / Anhalt OT. Stackelitz"
"country" => "Deutschland"
"birthday" => "1970-06-07"
]
csv文件中的原始zip值为:“ D-06846”