PHPackages                             avadim/fast-excel-laravel - 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. [PDF &amp; Document Generation](/categories/documents)
4. /
5. avadim/fast-excel-laravel

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

avadim/fast-excel-laravel
=========================

Lightweight and very fast XLSX Excel Spreadsheet Export/Import for Laravel

v2.14.1(2mo ago)4058.8k↓47.9%101MITPHPPHP &gt;=7.4

Since Jun 13Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/aVadim483/fast-excel-laravel)[ Packagist](https://packagist.org/packages/avadim/fast-excel-laravel)[ Docs](https://github.com/aVadim483/fast-excel-laravel)[ RSS](/packages/avadim-fast-excel-laravel/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (18)Versions (21)Used By (1)

[![FastExcelLaravel](logo/logo-laravel.jpg)](logo/logo-laravel.jpg)FastExcelLaravel
================

[](#fastexcellaravel)

Lightweight and very fast XLSX Excel Spreadsheet read/write library for Laravel in pure PHP (wrapper around [FastExcelWriter](https://packagist.org/packages/avadim/fast-excel-writer)and [FastExcelReader](https://packagist.org/packages/avadim/fast-excel-reader))

Introduction
------------

[](#introduction)

Exporting data from your Laravel application has never been so fast! Importing models into your Laravel application has never been so easy!

This library is a wrapper around **avadim/fast-excel-writer** and **avadim/fast-excel-reader**, so it's also lightweight, fast, and requires a minimum of memory. Using this library, you can export arrays, collections and models to a XLSX-file from your Laravel application, and you can import data to Laravel application.

**Features**

- Writing
    - Easily export models, collections and arrays to Excel
    - Export huge datasets very fast, and using a minimum of memory
    - Сan create multiple sheets and supports basic column, row and cell styling
    - You can set the height of the rows and the width of the columns (including auto width calculation)
    - Mapping export data
    - You can add active hyperlinks, formulas, notes and images to output XLSX-files
    - Supports workbook and sheet protection with/without passwords
    - Supports page settings – page margins, page size
    - Inserting multiple charts
    - Supports data validations and conditional formatting
- Reading
    - Import workbooks and worksheets to Eloquent models very quickly and with minimal memory usage
    - Automatic field detection from imported table headers
    - Import huge files very fast, and using a minimum of memory
    - Mapping import data
    - Supports auto formatter and custom formatter of datetime values for import data
    - The library can define and extract images from XLSX files
- Mapping import/export data

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

[](#installation)

Install via composer:

```
composer require avadim/fast-excel-laravel

```

And then you can use facade `Excel`

```
// Create a new workbook...
$excel = \Excel::create();

// export model...
$excel->sheet()->withHeadings()->exportModel(Users::class);

// and save XLSX-file to default storage
$excel->saveTo('path/file.xlsx');

// or save file to specified disk
$excel->store('disk', 'path/file.xlsx');

// Open an existing workbook
$excel = \Excel::open(storage_path('path/file.xlsx'));

// import records to database
$excel->withHeadings()->importModel(User::class);
```

Jump To:

- [Export Data](#export-data)
    - [Export a Model](#export-a-model)
    - [Export Any Collections and Arrays](#export-any-collections-and-arrays)
    - [Mapping Export Data](#mapping-export-data)
    - [Advanced Usage for Data Export](#advanced-usage-for-data-export)
- [Import Data](#import-data)
    - [Import a Model](#import-a-model)
    - [Mapping Import Data](#mapping-import-data)
    - [Advanced Usage for Data Import](#advanced-usage-for-data-import)
- [More Features](#more-features)
- [Do you want to support FastExcelLaravel?](#do-you-want-to-support-fastexcellaravel)

You can find [API references here](/docs/90-api-reference.md)

Export Data
-----------

[](#export-data)

### Export a Model

[](#export-a-model)

Easy and fast export of a model. This way you export only model data without headers and without any styling

```
// Create workbook with sheet named 'Users'
$excel = \Excel::create('Users');

// Export all users to Excel file
$sheet->exportModel(Users::class);

$excel->saveTo('path/file.xlsx');
```

The following code will write the field names and styles (font and borders) to the first row, and then export all the data of the User model

```
// Create workbook with sheet named 'Users'
$excel = \Excel::create('Users');

// Write users with field names in the first row
$sheet->withHeadings()
    ->applyFontStyleBold()
    ->applyBorder('thin')
    ->exportModel(Users::class);

$excel->saveTo('path/file.xlsx');
```

### Export Any Collections and Arrays

[](#export-any-collections-and-arrays)

```
// Create workbook with sheet named 'Users'
$excel = \Excel::create('Users');

$sheet = $excel->sheet();
// Get users as collection
$users = User::where('age', '>', 35)->get();

// Write attribute names
$sheet->writeRow(array_keys(User::getAttributes()));

// Write all selected records
$sheet->writeData($users);

$sheet = $excel->makeSheet('Records');
// Get collection of records using Query Builder
$records = \DB::table('users')->where('age', '>=', 21)->get(['id', 'name', 'birthday']);
$sheet->writeData($records);

$sheet = $excel->makeSheet('Collection');
// Make custom collection of arrays
$collection = collect([
    [ 'id' => 1, 'site' => 'google.com' ],
    [ 'id' => 2, 'site.com' => 'youtube.com' ],
]);
$sheet->writeData($collection);

$sheet = $excel->makeSheet('Array');
// Make array and write to sheet
$array = [
    [ 'id' => 1, 'name' => 'Helen' ],
    [ 'id' => 2, 'name' => 'Peter' ],
];
$sheet->writeData($array);

$sheet = $excel->makeSheet('Callback');
$sheet->writeData(function () {
    foreach (User::cursor() as $user) {
        yield $user;
    }
});
```

### Mapping Export Data

[](#mapping-export-data)

You can map the data that needs to be added as row

```
$sheet = $excel->sheet();
$sheet->mapping(function($model) {
    return [
        'id' => $model->id, 'date' => $model->created_at, 'name' => $model->first_name . $model->last_name,
    ];
})->exportModel(User::class);
$excel->save($testFileName);
```

### Advanced Usage for Data Export

[](#advanced-usage-for-data-export)

See detailed documentation for avadim/fast-excel-writer here:

```
$excel = \Excel::create('Users');
$sheet = $excel->sheet();

// Set column B to 12
$sheet->setColWidth('B', 12);
// Set styles for column C
$sheet->setColDataStyle('C', ['width' => 12, 'text-align' => 'center']);
// Set column width to auto
$sheet->setColWidth('D', 'auto');

$title = 'This is demo of avadim/fast-excel-laravel';
// Begin area for direct access to cells
$area = $sheet->beginArea();
$area->setValue('A2:D2', $title)
      ->applyFontSize(14)
      ->applyFontStyleBold()
      ->applyTextCenter();

// Write headers to area, column letters are case independent
$area
    ->setValue('a4:a5', '#')
    ->setValue('b4:b5', 'Number')
    ->setValue('c4:d4', 'Movie Character')
    ->setValue('c5', 'Birthday')
    ->setValue('d5', 'Name')
;

// Apply styles to headers
$area->withRange('a4:d5')
    ->applyBgColor('#ccc')
    ->applyFontStyleBold()
    ->applyOuterBorder('thin')
    ->applyInnerBorder('thick')
    ->applyTextCenter();

// Write area to sheet
$sheet->writeAreas();

// You can set value formats for some fields
$sheet->formatAttributes(['birthday' => '@date', 'number' => '@integer']);

// Write data to sheet
$sheet->writeData($data);

// Save XLSX-file
$excel->saveTo($testFileName);
```

Import Data
-----------

[](#import-data)

### Import a Model

[](#import-a-model)

To import models, you can use method `importModel()`. If the first row contains the names of the fields you can apply these using method `withHeadings()`

[![import.jpg](import.jpg)](import.jpg)

```
// Open XLSX-file
$excel = Excel::open($file);

// Import a workbook to User model using the first row as attribute names
$excel->withHeadings()->importModel(User::class);

// Done!!!
```

You can define the columns or cells from which you will import

```
// Import row to User model from columns range A:B - only 'name' and 'birthday'
$excel->withHeadings()->importModel(User::class, 'A:B');
```

[![import2.jpg](import2.jpg)](import2.jpg)

```
// Import from cells range
$excel->withHeadings()->importModel(User::class, 'B4:D7');

// Define top left cell only
$excel->withHeadings()->importModel(User::class, 'B4');
```

In the last two examples, we also assume that the first row of imported data (row 4) is the names of the attributes.

### Mapping Import Data

[](#mapping-import-data)

However, you can set the correspondence between columns and field names yourself.

```
// Import row to User model from columns range B:E
$excel->mapping(function ($record) {
    return [
        'id' => $record['A'], 'name' => $record['B'], 'birthday' => $record['C'], 'random' => $record['D'],
    ];
})->importModel(User::class, 'B:D');

// Define top left cell only
$excel->mapping(['B' => 'name', 'C' => 'birthday', 'D' => 'random'])->importModel(User::class, 'B5');

// Define top left cell only (shorter way)
$excel->importModel(User::class, 'B5', ['B' => 'name', 'C' => 'birthday', 'D' => 'random']);
```

### Advanced Usage for Data Import

[](#advanced-usage-for-data-import)

See detailed documentation for avadim/fast-excel-reader here:

```
$excel = Excel::open($file);

$sheet = $excel->sheet('Articles');
$sheet->setReadArea('B5');
foreach ($sheet->nextRow() as $rowNum => $rowData) {
    $user = User::create([
        'name' => $rowData['B'],
        'birthday' => new \Carbon($rowData['C']),
        'password' => bcrypt($rowData['D']),
    ]);
    Article::create([
        'user_id' => $user->id,
        'title' => $rowData['E'],
        'date' => new \Carbon($rowData['F']),
        'public' => $rowData['G'] === 'yes',
    ]);
}
```

More Features
-------------

[](#more-features)

You can see more features for export in the documentation for [FastExcelWriter](https://packagist.org/packages/avadim/fast-excel-writer).

You can see more features for import in the documentation for [FastExcelReader](https://packagist.org/packages/avadim/fast-excel-reader))

Do you want to support FastExcelLaravel?
----------------------------------------

[](#do-you-want-to-support-fastexcellaravel)

if you find this package useful you can support and donate to me for a cup of coffee:

- USDT (TRC20) TSsUFvJehQBJCKeYgNNR1cpswY6JZnbZK7
- USDT (ERC20) 0x5244519D65035aF868a010C2f68a086F473FC82b
- ETH 0x5244519D65035aF868a010C2f68a086F473FC82b

Or just give me a star on GitHub :)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance83

Actively maintained with recent releases

Popularity44

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.4% 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

Every ~57 days

Recently: every ~19 days

Total

19

Last Release

87d ago

Major Versions

v1.0.0 → v2.0.02023-07-01

PHP version history (2 changes)v1.0.0PHP ^7.4|^8.1

v2.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/bdb51a3c707497a4cc826ec61af31a3f33f2a372d8245e1d17a51be913d1c916?d=identicon)[avadim](/maintainers/avadim)

---

Top Contributors

[![aVadim483](https://avatars.githubusercontent.com/u/2246758?v=4)](https://github.com/aVadim483 "aVadim483 (32 commits)")[![rickgoemans](https://avatars.githubusercontent.com/u/7813679?v=4)](https://github.com/rickgoemans "rickgoemans (2 commits)")[![baradhili](https://avatars.githubusercontent.com/u/666900?v=4)](https://github.com/baradhili "baradhili (1 commits)")

---

Tags

excelexcel-exportexcel-importlaravellaravel-packagephplaravelexportexcelxlsxspreadsheetimportPHPExcelMS Officeoffice 2007

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.9k157.3M892](/packages/maatwebsite-excel)[avadim/fast-excel-writer

Lightweight and very fast XLSX Excel Spreadsheet Writer in PHP

3051.4M11](/packages/avadim-fast-excel-writer)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[avadim/fast-excel-reader

Lightweight and very fast XLSX Excel Spreadsheet and CSV Reader in PHP

107737.8k11](/packages/avadim-fast-excel-reader)[avadim/fast-excel-templator

Lightweight and very fast Excel Spreadsheet generator from XLSX-templates in PHP

20132.9k](/packages/avadim-fast-excel-templator)[api-platform/laravel

API Platform support for Laravel

58171.4k14](/packages/api-platform-laravel)

PHPackages © 2026

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