目前,我可以从这种格式的 excel 文件中获取数据。
这是我的工作代码。
$validator = Validator::make(
[
'file' => $request->file,
'extension' => strtolower($request->file->getClientOriginalExtension()),
],
[
'file' => 'required|max:5000',
'extension' => 'required|in:,csv,xlsx,xls',
]
);
$modal = "active";
if($validator->fails()){
return redirect()
->back()
->with(['errors'=>$validator->errors()->all()])
->with('modal',$modal);
}
$dateTime = date('Ymd_His');
$file = $request->file('file');
$fileName = $dateTime . '-' . $file->getClientOriginalName();
$savePath = public_path('/upload/projectlist/');
$file->move($savePath, $fileName);
$excel = Importer::make('Excel');
$excel->hasHeader(true);
$excel->load($savePath.$fileName);
$collection = $excel->getCollection();
if(sizeof($collection[1]) == 5)
{
$arr = json_decode($collection,true);
foreach ($arr as $row) {
$insert_data[] = array(
'first_name' => $row['first_name'],
'last_name' => $row['last_name'],
'email' => $row['email'],
'birthdate' => $row['birthdate']['date'],
'created_at' => now(),
'updated_at' => now(),
);
}
DB::table('tbl_sampleimport')->insert($insert_data);
}
else
{
return redirect()
->back()
->with(['errors'=> [0=> 'Please provide date in file according to your format.']])
->with('modal',$modal);
}
return redirect()->back()
->with(['success'=>'File uploaded successfully!'])
->with('modal',$modal);
现在格式已经改变了。添加了一些具有单个值的字段。喜欢Project Name
,Project Date
我正在努力获得它的价值。只想获取该值,但不必将其也保存到数据库中。
如何获取Project Name
并Project Date
声明为变量的值。并且仍然能够保存和的j.doe17
数据j.doe18
?
我使用cyber-duck 作为我的laravel/excel 进行导入等等。