Laravel PHPExcel 使用



Installation

Require this package in your composer.json and update composer. This will download the package and PHPExcel of PHPOffice.

"maatwebsite/excel": "~2.0.0"

After updating composer, add the ServiceProvider to the providers array in config/app.php

'Maatwebsite\Excel\ExcelServiceProvider',

You can use the facade for shorter code. Add this to your aliases:

'Excel' => 'Maatwebsite\Excel\Facades\Excel',

The class is bound to the ioC as excel

$excel = App::make('excel');

To publish the config settings in Laravel 5 use:

php artisan vendor:publish

This will add an excel.php config file to your config folder.

注:  app裏面設置好後providers,aliases設置好後,在需要用到的控制器裏use Excel;之後就可以直接用了,如:導出
Excel::create($filename, function($excel) use($data) {
        $excel->sheet('Sheetname', function($sheet) use($data) {
            $sheet->fromArray($data);
        });

    })->download('xls');


1.Excel可以支持100萬行記錄,Excel 2003最大支持65536行,從2007版開始支持104萬行,Excel極限是65536條。
發佈了7 篇原創文章 · 獲贊 1 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章