Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Excel Laravel Package

maatwebsite/excel

Laravel Excel is a Laravel wrapper for PhpSpreadsheet that makes Excel/CSV exports and imports simple and fast. Export collections or queries with automatic chunking, handle large datasets efficiently, and integrate cleanly into your Laravel apps.

View on GitHub
Deep Wiki
Context7

maatwebsite/excel is a Laravel wrapper around PhpSpreadsheet for fast, elegant Excel/CSV imports and exports. It integrates naturally with Laravel collections, Eloquent queries, and queues to handle large datasets reliably while keeping your code clean.

Use it to generate spreadsheets, import structured data, and optimize performance with chunking and batching—all with a consistent Laravel-friendly API.

  • Export Collections and arrays to XLSX/CSV
  • Export Eloquent queries with automatic chunking
  • Import files into models/collections with mapping & validation
  • Run imports/exports via queues for large jobs
  • Customize sheets (headings, formatting, multiple sheets)
Frequently asked questions about Excel
How do I export a Laravel Eloquent query to Excel with automatic chunking?
Use the `FromQuery` export class and pass your Eloquent query builder instance. The package handles chunking automatically to optimize memory usage. For example: `return Excel::download(new UsersExport($query));`. Ensure your query uses `cursor()` if needed for very large datasets.
Can I validate imported Excel data before saving to the database?
Yes, use the `WithValidation` trait in your import class. Define validation rules in the `rules()` method, and the package will halt processing on failures. Failed rows trigger `FailedImport` events for logging or alerts. Example: `use WithValidation; public function rules(): array { return ['email' => 'required|email']; }`
What Laravel versions does maatwebsite/excel support, and how do I check compatibility?
The package officially supports Laravel 10+ (v3.1.x). For Laravel 8/9, use v3.1.x with PHP 8.0+. Check the [release notes](https://github.com/SpartnerNL/Laravel-Excel/releases) for version-specific requirements. Run `composer require maatwebsite/excel` and verify your `laravel/framework` version in `composer.json`.
How do I handle large Excel imports (e.g., 500K+ rows) without memory issues?
Use the `WithChunkReading` trait to process rows in chunks (e.g., 1000 at a time). For background processing, dispatch the import as a queued job: `Excel::queue(new LargeImport, $file, 'high')->onQueue('imports')`. Ensure your queue worker has sufficient memory (e.g., `queue:work --memory=512M`).
Is there a way to customize Excel sheet formatting (e.g., colors, fonts, formulas) in exports?
Yes, use the `WithStyles` or `WithFormatData` traits. For example, apply bold headers with `public function headings(): array { return ['Name', 'Email']; }` and `public function styles(Sheet $sheet) { $sheet->getStyle('A1:B1')->applyFromArray(['font' => ['bold' => true]]); }`. For formulas, use `WithFormatData` and the `setValue()` method.
How do I test Excel exports/imports in Laravel’s PHPUnit?
Use the package’s built-in assertions like `assertExported()` or `assertImported()`. Mock file uploads with `Storage::fake()` and `UploadedFile::fake()`. Example: `$this->assertExported($export, function (Array $rows) { return count($rows) === 10; });`. For imports, verify database changes with `assertDatabaseHas()`.
Can I export Excel files directly to cloud storage (e.g., S3) instead of local disk?
Yes, leverage Laravel’s filesystem configuration. Store the file path in a temporary location, then move it to S3 using `Storage::disk('s3')->put()`. Example: `Excel::store(new UsersExport, 'exports/users.xlsx', 's3');`. Ensure your `config/filesystems.php` is properly configured for S3.
What are the alternatives to maatwebsite/excel for Laravel Excel handling?
Alternatives include **Box/Spout** (lighter, CSV-focused) and **RaphaelStolt/MaatwebsiteExcel** (fork with additional features). However, **maatwebsite/excel** stands out for its deep Laravel integration (Eloquent, Queues, Events) and PhpSpreadsheet’s robust Excel support. For CSV-only needs, Spout may suffice, but it lacks Excel-specific features like formulas or multi-sheet exports.
How do I log or alert on failed Excel import rows?
Listen to the `FailedImport` event in your `EventServiceProvider`. Example: `protected $listen = [FailedImport::class => [ImportFailedListener::class],];`. In the listener, log failed rows to a database table or send alerts via Laravel Notifications. Access failed rows via `$event->failures()`.
Does maatwebsite/excel support dynamic Excel generation from Blade views?
Yes, use the `FromView` export class to render Blade templates as Excel files. Example: `return Excel::download(new UserViewExport, 'users.xlsx');`. Define your view with `public function view(): string { return view('exports.users'); }`. This is useful for generating reports with dynamic data and styling.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport