ExcelController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Exports\GoodsNeateningExcelExport;
  4. use App\GoodsNeateningExcel;
  5. use Carbon\Carbon;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Storage;
  9. use Maatwebsite\Excel\Facades\Excel;
  10. use function foo\func;
  11. class ExcelController extends Controller
  12. {
  13. /**
  14. * Display a listing of the resource.
  15. *
  16. * @return \Illuminate\Http\Response
  17. */
  18. public function index()
  19. {
  20. }
  21. /**
  22. * Show the form for creating a new resource.
  23. *
  24. * @return \Illuminate\Http\Response
  25. */
  26. public function create()
  27. {
  28. }
  29. /**
  30. * Store a newly created resource in storage.
  31. *
  32. * @param \Illuminate\Http\Request $request
  33. * @return \Illuminate\Http\Response
  34. */
  35. public function store(Request $request)
  36. {
  37. //
  38. }
  39. public function makeExcel()
  40. {
  41. ini_set('memory_limit', '512M');
  42. $goodsesExcelArray=[['barcode','weight','id','key','time','url']];
  43. $handler=fopen('d:/newdws10.json','r');
  44. $json = fread($handler, filesize('d:/newdws10.json'));
  45. $json = '[' . $json . ']';
  46. $jsonArr=json_decode($json,true);
  47. foreach ($jsonArr as $obj){
  48. $url = $obj['url']??'';
  49. $barcode=$obj['barcode'].' ';
  50. array_push($goodsesExcelArray,[$barcode,$obj['weight'],$obj['id'].' '
  51. ,$obj['key'],$obj['time'], $url]);
  52. }
  53. Excel::store(new GoodsNeateningExcelExport($goodsesExcelArray),'exportedJson.xlsx','public');
  54. return ['result'=>'success'];
  55. }
  56. /**
  57. * Display the specified resource.
  58. *
  59. * @param \App\GoodsNeateningExcel $goodsNeateningExcel
  60. * @return \Illuminate\Http\Response
  61. */
  62. public function show(GoodsNeateningExcel $goodsNeateningExcel)
  63. {
  64. //
  65. }
  66. /**
  67. * Show the form for editing the specified resource.
  68. *
  69. * @param \App\GoodsNeateningExcel $goodsNeateningExcel
  70. * @return \Illuminate\Http\Response
  71. */
  72. public function edit(GoodsNeateningExcel $goodsNeateningExcel)
  73. {
  74. //
  75. }
  76. /**
  77. * Update the specified resource in storage.
  78. *
  79. * @param \Illuminate\Http\Request $request
  80. * @param \App\GoodsNeateningExcel $goodsNeateningExcel
  81. * @return \Illuminate\Http\Response
  82. */
  83. public function update(Request $request, GoodsNeateningExcel $goodsNeateningExcel)
  84. {
  85. //
  86. }
  87. /**
  88. * Remove the specified resource from storage.
  89. *
  90. * @param \App\GoodsNeateningExcel $goodsNeateningExcel
  91. * @return \Illuminate\Http\Response
  92. */
  93. public function destroy(GoodsNeateningExcel $goodsNeateningExcel)
  94. {
  95. //
  96. }
  97. }