rap2hpoutre/fast-excel
Fast, memory-efficient Excel/CSV/ODS import/export for Laravel using Spout. Export Eloquent models or collections to XLSX/CSV/ODS with custom column mapping, and download from controllers. Import files to collections, configure CSV options, or transform rows into DB inserts.
FastExcel::) and global helper (fastexcel()) reduce cognitive overhead, accelerating developer adoption.yield) enables custom middleware for logging, validation, or async processing.// Before (Laravel Excel)
Excel::download(new UserExport, 'users.xlsx');
// After (FastExcel)
return (new FastExcel(User::all()))->download('users.xlsx');
download() method integrates with Laravel’s response system, supporting file downloads, API responses, and queued exports (via Laravel Queues).import() + create() pattern enables direct database seeding from Excel/CSV, simplifying ETL workflows for bulk operations.with() methods).| Risk | Mitigation Strategy |
|---|---|
| PHP 8+ Dependency | Audit legacy code for PHP 7.1/7.4 dependencies; prioritize migration to PHP 8.1+ for new features. |
| Memory Leaks in Large Exports | Use yield-based chunking for exports >50K rows; monitor memory with memory_get_peak_usage(). |
| CSV Encoding Issues | Validate input files with configureCsv() for non-UTF-8 encodings (e.g., gbk). |
| Multi-Sheet Complexity | Document workarounds for multi-sheet exports (e.g., SheetCollection + manual mapping). |
| Spout Underlying Dependencies | Monitor Spout v3 updates for breaking changes; test with box/spout:^3.0. |
| Lack of Event Hooks | Implement custom middleware for row-level events (e.g., logging, validation). |
Performance Requirements:
Feature Scope:
Integration Impact:
Operational Trade-offs:
Long-Term Strategy:
box/spout:^3.0 (lightweight, ~5MB).User::cursor() for chunked exports).download() method integrates with Laravel’s response system, supporting:
return (new FastExcel(...))->download('file.xlsx');).| Step | Action | Effort | Risk |
|---|---|---|---|
| 1. Dependency Add | composer require rap2hpoutre/fast-excel |
Low | None |
| 2. Facade Setup | Add to config/app.php (optional) |
Low | None |
| 3. Pilot Replacement | Replace 1–2 high-volume exports (e.g., admin reports) with FastExcel. | Medium | Performance validation |
| 4. Chunking Strategy | Implement yield-based exports for >50K rows (e.g., User::cursor()). |
Medium | Memory leaks (mitigated) |
| 5. CSV/ODS Testing | Validate custom delimiters/encodings for global/localized deployments. | Low | Encoding issues (mitigated) |
| 6. Full Rollout | Replace all Laravel Excel/PhpSpreadsheet calls in the codebase. | High | Integration debt |
| 7. Monitoring | Add memory/performance metrics for large exports (e.g., New Relic, Laravel Debugbar). | Low | None |
Laravel Excel presets).import() + create()).yield).^3.0 in `How can I help you explore Laravel packages today?