PHPackages                             patosmack/laravel-excel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. patosmack/laravel-excel

AbandonedLibrary[Database &amp; ORM](/categories/database)

patosmack/laravel-excel
=======================

This package provides a way to export an Eloquent collection as an excel file and to import a Excel file as an Eloquent collection.

1.1.1(8y ago)17.5k↓50%[1 issues](https://github.com/patosmack/laravel-excel/issues)MITPHPPHP &gt;=5.4.0

Since Jul 16Pushed 7y ago1 watchersCompare

[ Source](https://github.com/patosmack/laravel-excel)[ Packagist](https://packagist.org/packages/patosmack/laravel-excel)[ RSS](/packages/patosmack-laravel-excel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

Laravel Excel ( THIS PROJECT HAS BEEN DISCONTINUED )
====================================================

[](#laravel-excel--this-project-has-been-discontinued-)

[![Latest Stable Version](https://camo.githubusercontent.com/f429908de2753c73d2373c08a14307f222e89c4f4048099b7295868dc29d1993/68747470733a2f2f706f7365722e707567782e6f72672f63796265722d6475636b2f6c61726176656c2d657863656c2f762f737461626c65)](https://packagist.org/packages/cyber-duck/laravel-excel)[![Total Downloads](https://camo.githubusercontent.com/5825aaecaf94bf0e78679acad42890d25dcfa160d19ac96610140c2df577bd2e/68747470733a2f2f706f7365722e707567782e6f72672f63796265722d6475636b2f6c61726176656c2d657863656c2f646f776e6c6f616473)](https://packagist.org/packages/cyber-duck/laravel-excel)[![License](https://camo.githubusercontent.com/9f0aba68a496bee026fbb3c38c2faa1857bf4e0bc15bf9ff0d984848dc291c78/68747470733a2f2f706f7365722e707567782e6f72672f63796265722d6475636b2f6c61726176656c2d657863656c2f6c6963656e7365)](https://raw.githubusercontent.com/Cyber-Duck/laravel-excel/master/LICENSE)

Exporting and importing Excel, CSV and OpenOffice stylesheets using Eloquent Collections and Query Builders in Laravel (5.\* and 4.\*).
It's based on [box/spout](https://github.com/box/spout).

Author: [Simone Todaro](https://github.com/SimoTod)
Contributors: [Clément Blanco](https://github.com/Claymm)
Made with ❤️ by [Cyber-Duck Ltd](http://www.cyber-duck.co.uk)

[Installation](#installation)
[Export Excel](#export-excel)
[Import Excel](#import-excel)
[Different formats](#different-formats)

Installation
------------

[](#installation)

Use composer to download the package:

```
composer require patosmack/laravel-excel

```

Register the service provider in `config/app.php` adding *Patosmack\\LaravelExcel\\ExcelServiceProvider* to the provider array.

Note. If you are on Laravel 4, use *Patosmack\\LaravelExcel\\ExcelLegacyServiceProvider*

Export Excel
------------

[](#export-excel)

### Generate and download an excel file

[](#generate-and-download-an-excel-file)

Add

```
use Exporter;

```

to your controller.

In your controler function, create a new excel file from an Eloquent collection.

```
$excel = Exporter::make('Excel');
$excel->load($yourCollection);
return $excel->stream($yourFileName);

```

The exporter class is fluent, so you can also write

```
return Exporter::make('Excel')->load($yourCollection)->stream($yourFileName);

```

The exporter class supports Query builder objects as well

```
$query = DB:table('table')->select('col1','col2');
$excel = Exporter::make('Excel');
$excel->loadQuery($query);
return $excel->stream($yourFileName);

```

If you deal with big tables, you can set the chunk size to minimise the memory usage

```
$query = DB:table('table')->select('col1','col2');
$excel = Exporter::make('Excel');
$excel->loadQuery($query);
$excel->setChunk(1000);
return $excel->stream($yourFileName);

```

### Generate and save an excel file

[](#generate-and-save-an-excel-file)

To save the excel file on the server, use the save method.

```
return $excel->save($yourFileNameWithPath);

```

### Advanced usage

[](#advanced-usage)

By default, every element of the Collection becomes a row and every unprotected field of the Model becomes a cell.
No headers row is printed.

To change this behaviour, create a class extending *Cyberduck\\LaravelExcel\\Contract\\SerialiserInterface*, implement the methods *getHeaderRow()* and *getData(Model $data)* and set this class on the excel object usint *setSerialiser()*.

```
$serialiser = new CustomSerialiser();
$excel = Exporter::make('Excel');
$excel->load($collection);
$excel->setSerialiser($serialiser);
return $excel->stream($yourFileName);

```

*getHeaderRow()* must return an array of string where every element is a cell of the first row. To not print the header row, simply return a void array *\[\]*.
*getData(Model $data)* must return an array of string, and every elements is a cell.

Example

```
namespace App\Serialisers;

use Illuminate\Database\Eloquent\Model;
use Cyberduck\LaravelExcel\Contract\SerialiserInterface;

class ExampleSerialiser implements SerialiserInterface
{
    public function getData(Model $data)
    {
        $row = [];

        $row[] = $data->field1;
        $row[] = $data->relationship->field2;

        return $row;
    }

    public function getHeaderRow()
    {
        return [
            'Field 1',
            'Field 2 (from a relationship)'
        ];
    }
}

```

Import Excel
------------

[](#import-excel)

Add

```
use Importer;

```

to your controller.

In your controler function, import an excel file.

```
$excel = Importer::make('Excel');
$excel->load($filepath);
$collection = $excel->getCollection();
//dd($collection)

```

The importer class is fluent, then you can also write

```
return Importer::make('Excel')->getCollection($filepath)->getCollection();

```

### Advanced usage

[](#advanced-usage-1)

By default, every row of the first sheet of the excel file becomes an array and the final result is wraped in a Collection (Illuminate\\Support\\Collection).

To import a different sheet, use *setSheet($sheet)*

```
$excel = Importer::make('Excel');
$excel->load($filepath);
$excel->setSheet($sheetNumber);
$collection = $excel->getCollection();
//dd($collection)

```

To import each row in an Eloquent model, create a class extending *Cyberduck\\LaravelExcel\\Contract\\ParserInterface* and implement the methods *transform($row)*.

Example

```
namespace App\Parsers;

use App\Models\YourModel;
use Cyberduck\LaravelExcel\Contract\ParserInterface;

class ExampleSerialiser implements ParserInterface
{
    public function transform($row)
    {
        $model = new YourModel();
        $model->field1 = $row[0];
        $model->field2 = $row[1];
        // We can manunipulate the data before returning the object
        $model->field3 = new \Carbon($row[2]);
        return $model;
    }
}

```

Different formats
-----------------

[](#different-formats)

The package supports ODS and CSV files.

### ODS

[](#ods)

```
$exporter = Exporter::make('OpenOffice');
$importer = Importer::make('OpenOffice');

```

### CSV

[](#csv)

```
$exporter = Exporter::make('Csv');
$importer = Importer::make('Csv');

```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3222d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9f58976de162983e14a37dffc949690c8a5b34a44e6bf9f332280b4daf779f3a?d=identicon)[patosmack](/maintainers/patosmack)

---

Top Contributors

[![patosmack](https://avatars.githubusercontent.com/u/11169024?v=4)](https://github.com/patosmack "patosmack (1 commits)")

---

Tags

laravelexporteloquentexcelexporterimportimporterspout

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/patosmack-laravel-excel/health.svg)

```
[![Health](https://phpackages.com/badges/patosmack-laravel-excel/health.svg)](https://phpackages.com/packages/patosmack-laravel-excel)
```

###  Alternatives

[cyber-duck/laravel-excel

This package provides a way to export an Eloquent collection as an excel file and to import a Excel file as an Eloquent collection.

74225.0k](/packages/cyber-duck-laravel-excel)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
