ExcelController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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('max_execution_time',2500);
  42. ini_set('memory_limit','1526M');
  43. $goodsesExcelArray=[['barcode','weight','id','key','time','url']];
  44. $handler=fopen('d:/201912.json','r');
  45. $json = fread($handler, filesize('d:/201912.json'));
  46. // $json = '[' . $json . ']';
  47. $jsonArr=json_decode($json,true);
  48. foreach ($jsonArr as $obj){
  49. $url = $obj['url']??'';
  50. $barcode=($obj['barcode']??'').' ';
  51. array_push($goodsesExcelArray,[$barcode,$obj['weight']??'',($obj['id']??'').' '
  52. ,($obj['key'])??'',($obj['time'])??'', ($url)??'']);
  53. }
  54. Excel::store(new GoodsNeateningExcelExport($goodsesExcelArray),'exportedJson.xlsx','public');
  55. return ['result'=>'success'];
  56. }
  57. /**
  58. * Display the specified resource.
  59. *
  60. * @param \App\GoodsNeateningExcel $goodsNeateningExcel
  61. * @return \Illuminate\Http\Response
  62. */
  63. public function show(GoodsNeateningExcel $goodsNeateningExcel)
  64. {
  65. //
  66. }
  67. /**
  68. * Show the form for editing the specified resource.
  69. *
  70. * @param \App\GoodsNeateningExcel $goodsNeateningExcel
  71. * @return \Illuminate\Http\Response
  72. */
  73. public function edit(GoodsNeateningExcel $goodsNeateningExcel)
  74. {
  75. //
  76. }
  77. /**
  78. * Update the specified resource in storage.
  79. *
  80. * @param \Illuminate\Http\Request $request
  81. * @param \App\GoodsNeateningExcel $goodsNeateningExcel
  82. * @return \Illuminate\Http\Response
  83. */
  84. public function update(Request $request, GoodsNeateningExcel $goodsNeateningExcel)
  85. {
  86. //
  87. }
  88. /**
  89. * Remove the specified resource from storage.
  90. *
  91. * @param \App\GoodsNeateningExcel $goodsNeateningExcel
  92. * @return \Illuminate\Http\Response
  93. */
  94. public function destroy(GoodsNeateningExcel $goodsNeateningExcel)
  95. {
  96. //
  97. }
  98. }