LaravelPackages

Laravel Excel 3.0 package

Laravel Excel is Laravel Flavoured PhpSpreadsheet

Laravel Excel 3.0

Laravel Excel is intended at being Laravel-flavoured PhpSpreadsheet: a simple, but elegant wrapper around PhpSpreadsheet with the goal of simplifying exports and  is open source and licensed under the MIT license.

PhpSpreadsheet is a library written in pure PHP and providing a set of classes that allow you to read from and to write to different spreadsheet file formats, like Excel and LibreOffice Calc.

Laravel Excel features:

  • Easily export collections to Excel
  • Export queries with automatic chunking for better performance
  • Queue exports for better performance
  • Easily export Blade views to Excel

Installation

composer require maatwebsite/excel

Requirements

  • PHP: ^7.1
  • Laravel: ^5.5
  • PhpSpreadsheet: ^1.2
  • PHP extension php_zip enabled
  • PHP extension php_xml enabled
  • PHP extension php_gd2 enabled
PHP version support

Support for PHP versions will only be maintained for a period of six months beyond the end-of-life of that PHP version.

Supported Versions

Versions will be supported for a limited amount of time.

VersionLaravel VersionPhp VersionSupport
2.1<=5.6<=7.0EOL on 15-05-2018
3.0^5.5^7.0New features

Service Provider

The Maatwebsite\Excel\ExcelServiceProvider is auto-discovered and registered by default, but if you want to register it yourself:

Add the ServiceProvider in config/app.php

'providers' => [
    /*
     * Package Service Providers...
     */
    Maatwebsite\Excel\ExcelServiceProvider::class,
]

Facade

The Excel facade is also auto-discovered, but if you want to add it manually:

★ READ ALSO ★  Very simple lightbox plugin without any dependencies

Add the Facade in config/app.php

'aliases' => [
    ...
    'Excel' => Maatwebsite\Excel\Facades\Excel::class,
]

Config

To publish the config, run the vendor publish command:

php artisan vendor:publish

This will create a new config file named config/excel.php.

Usage

You can use Excel in the following ways:

Via dependency injection:

public function __construct(\Maatwebsite\Excel\Excel $excel)
{
    $this->excel = $excel;
}

public function export()
{
    return $this->excel->export(new Export);
}

Via Exporter interface:

public function __construct(\Maatwebsite\Excel\Exporter $excel)
{
    $this->excel = $excel;
}

public function export()
{
    return $this->excel->export(new Export);
}

Via the Facade:

public function export()
{
    return Excel::export(new Export);
}

Via container binding:

 

$this->app->bind(Exporter::class, function() {
    return new Exporter($this->app['excel']);
});

 

Full documentation here  or Maatwebsite/Laravel-Excel

Tags

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close