PHPackages                             technofelia/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. technofelia/laravel-excel

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

technofelia/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.

061PHP

Since May 15Pushed 1y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Excel
=============

[](#laravel-excel)

[![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 cyber-duck/laravel-excel

```

### Laravel 4.x

[](#laravel-4x)

Register the service provider in `config/app.php` by adding this line to providers array.

```
'providers' => [
	Cyberduck\LaravelExcel\ExcelLegacyServiceProvider::class,
],
```

### Laravel &lt; 5.5

[](#laravel--55)

Register the service provider in `config/app.php` by adding this line to providers array.

```
'providers' => [
	Cyberduck\LaravelExcel\ExcelServiceProvider::class,
],
```

### Laravel &gt; 5.5

[](#laravel--55-1)

No need to register anything, since it used package auto discovery feature in Laravel 5.5.

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($data)
    {
        $row = [];

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

        return $row;
    }

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

```

then set the serialiser before saving the file the collection.

```
$collection = Exporter::make('Excel')->load($yourCollection)->setSerialiser(new ExampleSerialiser)->stream($yourFileName);

```

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')->load($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 ExampleParser implements ParserInterface
{
    public function transform($row, $header)
    {
        $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;
    }
}

```

then set the parser before creating the collection.

```
$collection = Importer::make('Excel')->load($filepath)->setParser(new ExampleParser)->getCollection();

```

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

16

—

LowBetter than 5% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3aca44ccb782bb1c18f678e44ea5e0cca5dd19ed21236e933dd919b7cd0b0d48?d=identicon)[faysalsadik](/maintainers/faysalsadik)

---

Top Contributors

[![SimoTod](https://avatars.githubusercontent.com/u/8427737?v=4)](https://github.com/SimoTod "SimoTod (22 commits)")[![faysalsadik](https://avatars.githubusercontent.com/u/61419805?v=4)](https://github.com/faysalsadik "faysalsadik (7 commits)")[![clemblanco](https://avatars.githubusercontent.com/u/668419?v=4)](https://github.com/clemblanco "clemblanco (5 commits)")[![worzy](https://avatars.githubusercontent.com/u/1092417?v=4)](https://github.com/worzy "worzy (4 commits)")[![joaodman](https://avatars.githubusercontent.com/u/6719189?v=4)](https://github.com/joaodman "joaodman (2 commits)")[![cyberduckneil](https://avatars.githubusercontent.com/u/90324469?v=4)](https://github.com/cyberduckneil "cyberduckneil (2 commits)")[![wsambian](https://avatars.githubusercontent.com/u/20776356?v=4)](https://github.com/wsambian "wsambian (1 commits)")[![kerog](https://avatars.githubusercontent.com/u/2870694?v=4)](https://github.com/kerog "kerog (1 commits)")[![Konafets](https://avatars.githubusercontent.com/u/363363?v=4)](https://github.com/Konafets "Konafets (1 commits)")[![matriphe](https://avatars.githubusercontent.com/u/277262?v=4)](https://github.com/matriphe "matriphe (1 commits)")[![mohammedjammeh](https://avatars.githubusercontent.com/u/41289378?v=4)](https://github.com/mohammedjammeh "mohammedjammeh (1 commits)")[![nadge](https://avatars.githubusercontent.com/u/3862793?v=4)](https://github.com/nadge "nadge (1 commits)")

### Embed Badge

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

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M542](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M209](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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