laravel5 中使用excel

http://www.maatwebsite.nl/laravel-excel/docs/getting-started
https://packagist.org/packages/maatwebsite/excel

下载

这里写图片描述
更新composer
或者直接在命令行中

composer require maatwebsite/excel

2配置

app/config/app.php
providers数组中添加
Maatwebsite\Excel\ExcelServiceProvider::class,
aliasses数组中添加:
‘Excel’ => Maatwebsite\Excel\Facades\Excel::class,

3、使用

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Maatwebsite\Excel\Facades\Excel;

class DemoController extends Controller
{
    public function getDemo(){
        return view("demo.demo");

    }
    public function getExcel(){
        // $excel = App::make('excel');
        Excel::create('Laravel Excel', function($excel) {

            $excel->sheet('Excel sheet', function($sheet) {

                $sheet->setOrientation('landscape');

            });

        })->export('xls');
    }
}

导出excel api地址
http://www.maatwebsite.nl/laravel-excel/docs/export
导入excel api地址
http://www.maatwebsite.nl/laravel-excel/docs/import

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页