Excel导出
来源:互联网 发布:淘宝店铺保证金怎么交 编辑:程序博客网 时间:2024/06/04 00:45
一.引入composer包:1.composer require -vvv //生成最新版本的 composer.json2.config/app.php: 'provider'=>:Maatwebsite\Excel\ExcelServiceProvider::class //服务 'aliases' =>:'Excel' => Maatwebsite\Excel\Facades\Excel::class //门面3.生成配置文件: php artisan vendor:publish //Excel.php 二.模板里: // 1.button按钮 id <form id="export"></form><button type="button" class="btn btn-warning btn-sm" onclick="exports()">导出</button>// 2.商品导出方法function exports(){ var data = $("#export").serialize(); location.href = "{{url("admin/goods/export")}}?"+data;}三.路由 Route::get("export","GoodsController@export")->name("goods.export"); 四.控制器 public function export(Goods $goods,NormsGroup $normsGroup,Request $request,GoodsType $goodsType,GoodsStatus $goodsStatus) { //获取商品分类 $goodsTypeInfo=$goodsType::whereNotIn("parent_id",[0,56])->get()->toArray(); //获取所有商品状态 $goodsStatusInfo=$goodsStatus::all()->toArray(); //获取商品分类 $info['name']=$request->input("name")?$request->input("name"):""; $info['id']=$request->input("id")?$request->input("id"):""; $info['category']=$request->input("category")?$request->input("category"):0; $info['status']=$request->input("status")?[$request->input("status")]:[1,2,3,4,5]; //获取商品列表 if ($info['id']) { if ($info['category']) { $goodsInfos=$goods::with("goodsStatus","goodsType")->where([["name","like","%{$info['name']}%"],["id",$info['id']],["f_goods_type_id",$info['category']]])->whereIn("f_goods_status_id",$info['status'])->get(); }else { $goodsInfos=$goods::with("goodsStatus","goodsType")->where([["name","like","%{$info['name']}%"],["id",$info['id']]])->whereIn("f_goods_status_id",$info['status'])->get(); } }else { if ($info['category']) { $goodsInfos=$goods::with("goodsStatus","goodsType")->where([["name","like","%{$info['name']}%"],["f_goods_type_id",$info['category']]])->whereIn("f_goods_status_id",$info['status'])->get(); }else { $goodsInfos=$goods::with("goodsStatus","goodsType")->where("name","like","%{$info['name']}%")->whereIn("f_goods_status_id",$info['status'])->get(); } } $goodsInfo=$goodsInfos->toArray(); foreach ($goodsInfo as $k =>$v) { $normsGroupId=explode(",",$v['f_norms_group_id']); $normsGroupInfo=$normsGroup->whereIn("id",$normsGroupId)->get()->toArray(); $goodsInfo[$k]["norms_group"]=$normsGroupInfo; } //整成一维数组 $data[]=[ '编号', '商品名称', '所属分类', '录入时间', '商品规格组合', '状态', '商品价格', '11121(价格)', ]; // foreach($goodsInfo as $k=>$v){ // $temp['id'] = $v['id']; // $temp['open_id'] = $v['open_id']; // $temp['goods_type'] = $v['goods_type']['name']; // $temp['create_time'] = date('Y-m-d',$v['create_time']); // $temp['norms_group']=""; // foreach ($v['norms_group'] as $kk=>$vv){ // $temp['norms_group'] .= $vv['name']."|"; // } // $temp['norms_group']=trim($temp['norms_group'],"|"); // $temp['status'] = $v['goods_status']['name']; // $temp['show_price'] = $v['show_price']; // $temp['show_sale_price'] = $v['show_sale_price']; // $data[] = $temp; // } //排行 用户成交额计算 number_format $i=0; foreach($employeeInfo as $k=>$v){ $temp_money["no"] = ++$i; $temp_money["username"] = $v['username']; $temp_money['userTurnover'] = number_format($price[$v['id']]/100,2,".",""); $temp_money['area1'] = ""; foreach($areaInfo as $kk=>$vv){ if ($v['f_area_id'] == $vv['id']){ $temp_money['area1'] = $vv['name']; } } $data[] = $temp_money; } Excel::create('goodsInfo',function($excel) use ($data){ $excel->sheet('goodsInfo', function($sheet) use ($data){ $sheet->rows($data); }); })->export('xls'); }
一.引入composer包:1.composer require -vvv //生成最新版本的 composer.json2.config/app.php: 'provider'=>:Maatwebsite\Excel\ExcelServiceProvider::class //服务 'aliases' =>:'Excel' => Maatwebsite\Excel\Facades\Excel::class //门面3.生成配置文件: php artisan vendor:publish //Excel.php 二.模板里: // 1.button按钮 id <form id="export"></form><button type="button" class="btn btn-warning btn-sm" onclick="exports()">导出</button>// 2.商品导出方法function exports(){ var data = $("#export").serialize(); location.href = "{{url("admin/goods/export")}}?"+data;}三.路由 Route::get("export","GoodsController@export")->name("goods.export"); 四.控制器 public function export(Goods $goods,NormsGroup $normsGroup,Request $request,GoodsType $goodsType,GoodsStatus $goodsStatus) { //获取商品分类 $goodsTypeInfo=$goodsType::whereNotIn("parent_id",[0,56])->get()->toArray(); //获取所有商品状态 $goodsStatusInfo=$goodsStatus::all()->toArray(); //获取商品分类 $info['name']=$request->input("name")?$request->input("name"):""; $info['id']=$request->input("id")?$request->input("id"):""; $info['category']=$request->input("category")?$request->input("category"):0; $info['status']=$request->input("status")?[$request->input("status")]:[1,2,3,4,5]; //获取商品列表 if ($info['id']) { if ($info['category']) { $goodsInfos=$goods::with("goodsStatus","goodsType")->where([["name","like","%{$info['name']}%"],["id",$info['id']],["f_goods_type_id",$info['category']]])->whereIn("f_goods_status_id",$info['status'])->get(); }else { $goodsInfos=$goods::with("goodsStatus","goodsType")->where([["name","like","%{$info['name']}%"],["id",$info['id']]])->whereIn("f_goods_status_id",$info['status'])->get(); } }else { if ($info['category']) { $goodsInfos=$goods::with("goodsStatus","goodsType")->where([["name","like","%{$info['name']}%"],["f_goods_type_id",$info['category']]])->whereIn("f_goods_status_id",$info['status'])->get(); }else { $goodsInfos=$goods::with("goodsStatus","goodsType")->where("name","like","%{$info['name']}%")->whereIn("f_goods_status_id",$info['status'])->get(); } } $goodsInfo=$goodsInfos->toArray(); foreach ($goodsInfo as $k =>$v) { $normsGroupId=explode(",",$v['f_norms_group_id']); $normsGroupInfo=$normsGroup->whereIn("id",$normsGroupId)->get()->toArray(); $goodsInfo[$k]["norms_group"]=$normsGroupInfo; } //整成一维数组 $data[]=[ '编号', '商品名称', '所属分类', '录入时间', '商品规格组合', '状态', '商品价格', '11121(价格)', ]; // foreach($goodsInfo as $k=>$v){ // $temp['id'] = $v['id']; // $temp['open_id'] = $v['open_id']; // $temp['goods_type'] = $v['goods_type']['name']; // $temp['create_time'] = date('Y-m-d',$v['create_time']); // $temp['norms_group']=""; // foreach ($v['norms_group'] as $kk=>$vv){ // $temp['norms_group'] .= $vv['name']."|"; // } // $temp['norms_group']=trim($temp['norms_group'],"|"); // $temp['status'] = $v['goods_status']['name']; // $temp['show_price'] = $v['show_price']; // $temp['show_sale_price'] = $v['show_sale_price']; // $data[] = $temp; // } //排行 用户成交额计算 number_format $i=0; foreach($employeeInfo as $k=>$v){ $temp_money["no"] = ++$i; $temp_money["username"] = $v['username']; $temp_money['userTurnover'] = number_format($price[$v['id']]/100,2,".",""); $temp_money['area1'] = ""; foreach($areaInfo as $kk=>$vv){ if ($v['f_area_id'] == $vv['id']){ $temp_money['area1'] = $vv['name']; } } $data[] = $temp_money; } Excel::create('goodsInfo',function($excel) use ($data){ $excel->sheet('goodsInfo', function($sheet) use ($data){ $sheet->rows($data); }); })->export('xls'); }
阅读全文
0 0
- 导出EXCEL
- Excel导出
- 导出Excel
- 导出EXCEL
- 导出Excel
- EXCEL导出
- 导出Excel
- 导出excel
- 导出excel
- EXCEL导出
- 导出excel
- 导出Excel
- Excel导出。
- 导出excel
- Excel 导出
- 导出excel
- 导出excel
- 导出excel
- MTK Android之GPIO驱动简介
- bundle小结
- 购物车真实数据添加
- spring学习基础(ioc底层原理,bean的配置和注解)
- tomcat9-jenkins:insufficient free space available after evicting expired cache entries-consider
- Excel导出
- UVa10943
- 最长子序列--动态规划
- powerdesigner16.01的安装,破译及汉化
- Lightoj1068——Investigation(数位dp)
- 1-3 数组的反序输出
- C++的multimap自定义key值
- base64在html的用法
- js多数组进行排列组合