php 使用 Maatwebsite\Excel上传excel文
作者:
顶尖少爷 | 来源:发表于
2020-06-02 18:18 被阅读0次直接上代码 上传excel 保存处理为json文件
$fileName="";
if(!empty($request->file("excel"))){
//base_path("public/storage/excel/demo.xlsx")
$excelUrl =$request->file("excel")->store("/public/storage/excel");
$items=Excel::toArray(new GameAppOptionImportRepository(),$excelUrl,"","");
foreach ($items[0] as $key=>$item){
if($key==0) continue;
$eventName = trim($item[0]);
if(!empty($item[1])){
$data[$eventName]["adjust"]=trim($item[1]);
}
if(!empty($item[2])){
$data[$eventName]["re_name"]=trim($item[2]);
}
}
$str = json_encode($data);
$fileName = "/storage/json/".$appId."_".$request->get("version").".json";
$jsonUrl = base_path("public".$fileName);
file_put_contents($jsonUrl,$str);
}
本文标题:php 使用 Maatwebsite\Excel上传excel文
本文链接:https://www.haomeiwen.com/subject/kvlpzhtx.html
网友评论