laravel5.4 导出 Excel 表格

1.执行 composer require maatwebsite/excel

laravel5.4 导出 Excel 表格

2. composer.json 文件出现(或者手动添加)

laravel5.4 导出 Excel 表格

3.在config目录下 app.php 添加参数

laravel5.4 导出 Excel 表格

laravel5.4 导出 Excel 表格

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');
    }
}

效果:

laravel5.4 导出 Excel 表格

参考:http://laravelacademy.org/post/2024.html

上一篇:Hardcoded string should use @string resource 警告


下一篇:ERROR 1130: Host ’...′ is not allowed to connect to this MySQL server