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

v4.1.0(3w ago)4263.3k↓46.1%91MITPHPPHP &gt;=8.1CI passing

Since Jun 13Pushed 3w 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 2w ago

READMEChangelog (10)Dependencies (24)Versions (24)Used By (1)

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

[](#fastexcellaravel)

**English** | [Русский](README.ru.md)

[![Tests](https://github.com/aVadim483/fast-excel-laravel/actions/workflows/tests.yml/badge.svg)](https://github.com/aVadim483/fast-excel-laravel/actions/workflows/tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/6f64a055c264499fc0dc8b05c8a72227fc96bd63bd54b4ddbfc06f8ac7039889/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61766164696d2f666173742d657863656c2d6c61726176656c)](https://packagist.org/packages/avadim/fast-excel-laravel)[![Total Downloads](https://camo.githubusercontent.com/e08d2c0a7ceff39c94017d95c1487744cc0ca911876ca7a16c053f760a4392d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61766164696d2f666173742d657863656c2d6c61726176656c)](https://packagist.org/packages/avadim/fast-excel-laravel)[![License](https://camo.githubusercontent.com/5dab4a5c1a9b5f4ccb7d16bb074fd1700952708595ad0c52060d685d29508205/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61766164696d2f666173742d657863656c2d6c61726176656c)](https://packagist.org/packages/avadim/fast-excel-laravel)

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
    - Reads XLSX, legacy XLS (Excel 97-2003) and CSV; the spreadsheet format is detected automatically from the file
    - 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

Requirements
------------

[](#requirements)

VersionPHPLaravel4.x&gt;= 8.110 – 133.x&gt;= 8.110 – 132.x&gt;= 7.46 – 13Installation
------------

[](#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)
    - [Download File](#download-file)
- [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)
    - [Reading CSV files](#reading-csv-files)
- [Configuration](#configuration)
- [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');
$sheet = $excel->sheet();

// 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');
$sheet = $excel->sheet();

// 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($users->first()->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);
```

### Download File

[](#download-file)

You can return the generated file as a download response right from a controller action

```
public function export()
{
    $excel = \Excel::create('Users');
    $excel->sheet()->withHeadings()->exportModel(User::class);

    // Returns Symfony\Component\HttpFoundation\BinaryFileResponse,
    // the temporary file will be deleted after sending
    return $excel->download('users.xlsx');
}
```

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()`

`Excel::open()` reads XLSX, legacy XLS (Excel 97-2003) and CSV files — the format is detected automatically from the file content, so the file extension does not matter. All the import methods below work the same way regardless of the source format (see [Reading legacy XLS files](/docs/80-reading-xls.md)and [Reading CSV files](/docs/81-reading-csv.md)).

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

```
// Open a workbook (XLSX, legacy XLS or CSV — the format is detected automatically)
$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 also set your own attribute names (in column order) — the first row is still skipped, but its values are ignored

```
$excel->withHeadings(['name', 'birthday', 'random'])->importModel(User::class);
```

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\Carbon($rowData['C']),
        'password' => bcrypt($rowData['D']),
    ]);
    Article::create([
        'user_id' => $user->id,
        'title' => $rowData['E'],
        'date' => new \Carbon\Carbon($rowData['F']),
        'public' => $rowData['G'] === 'yes',
    ]);
}
```

### Reading CSV files

[](#reading-csv-files)

A CSV file has no signature, so `Excel::open()` treats any file that is neither XLSX nor XLS as CSV. The whole import API — `withHeadings()`, `mapping()`, `importModel()`, read areas, `readRows()`, `nextRow()` — works exactly as it does for XLSX and XLS.

```
// A CSV file is detected automatically (no XLSX/XLS signature)
$excel = \Excel::open(storage_path('users.csv'));
$excel->withHeadings()->importModel(User::class);

// CSV options (delimiter, enclosure, encoding, ...) are passed as the second argument
$excel = \Excel::open($file, ['delimiter' => ';', 'encoding' => 'CP1251']);
$rows = $excel->readRows(true);
```

CSV reading requires `avadim/fast-excel-reader` `^4.3` (installed automatically). Global defaults for the CSV options can be set in `config('fast-excel.csv')`. Note that CSV carries no cell types or styles, so every value is read as a string; writing CSV is not supported (export is XLSX only). See [Reading CSV files](/docs/81-reading-csv.md).

Configuration
-------------

[](#configuration)

Optionally you can publish the config file

```
php artisan vendor:publish --provider="avadim\FastExcelLaravel\Providers\ExcelServiceProvider" --tag=config

```

Available options in `config/fast-excel.php`:

```
return [
    // Directory for temporary files created while reading and writing XLSX.
    // When null, storage_path('app/tmp/fast-excel') is used
    'temp_dir' => null,

    // Default options applied when reading CSV (merged into the options passed to
    // open(); a per-call option wins, a null value here keeps the reader default)
    'csv' => [
        'delimiter'        => null,   // null = auto-detect
        'enclosure'        => '"',
        'encoding'         => null,   // e.g. 'CP1251'; null = auto-detect
        'skip_empty_lines' => true,
        'comment_prefix'   => null,   // e.g. '#'
    ],
];
```

Stale temporary files (older than 24 hours, left after failed runs) are cleaned up automatically.

You can also override the temporary directory for a single workbook via options

```
$excel = \Excel::create('Users', ['temp_dir' => '/path/to/tmp']);
$excel = \Excel::open($file, ['temp_dir' => '/path/to/tmp']);
```

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

59

—

FairBetter than 98% of packages

Maintenance95

Actively maintained with recent releases

Popularity44

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 94.1% 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 ~54 days

Recently: every ~35 days

Total

22

Last Release

22d ago

Major Versions

v1.0.0 → v2.0.02023-07-01

v2.14.1 → v3.0.02026-07-19

v3.0.0 → v4.0.02026-07-25

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

v2.0.0PHP &gt;=7.4

v3.0.0PHP &gt;=8.1

### 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 (48 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.7k162.0M969](/packages/maatwebsite-excel)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M319](/packages/laravel-ai)[avadim/fast-excel-writer

Lightweight and very fast XLSX Excel Spreadsheet Writer in PHP

3081.5M13](/packages/avadim-fast-excel-writer)[moonshine/moonshine

Laravel administration panel

1.3k268.2k89](/packages/moonshine-moonshine)[avadim/fast-excel-reader

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

105786.0k14](/packages/avadim-fast-excel-reader)

PHPackages © 2026

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