1.执行 composer require maatwebsite/excel
2. composer.json 文件出现(或者手动添加)
3.在config目录下 app.php 添加参数
4.导出数据
<?php namespace App\Http\Controllers; use Excel; class ExcelController extends Controller { public function export() { $cellData = [ ['学号','姓名','成绩'], ['10001','AAAAA','99'], ['10002','BBBBB','92'], ['10003','CCCCC','95'], ['10004','DDDDD','89'], ['10005','EEEEE','96'], ]; Excel::create('学生成绩',function($excel) use ($cellData){ $excel->sheet('score', function($sheet) use ($cellData){ $sheet->rows($cellData); }); })->export('xls'); } }
效果: