ExcelController.php 2.9 KB

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