- How does FastExcel compare to Laravel Excel in terms of performance for large datasets?
- FastExcel outperforms Laravel Excel significantly, especially for large datasets. It uses Spout v3 for streaming and chunked processing, keeping memory usage low (e.g., 2MB peak for 1M+ rows) compared to Laravel Excel’s 123MB+ overhead. It’s ideal for high-volume exports like monthly reports or bulk data dumps.
- Can I use FastExcel to export Eloquent relationships or nested data?
- FastExcel focuses on flat exports of Eloquent models or Collections. For nested relationships, you’ll need to flatten the data manually in a callback before exporting. If you need complex Excel features like multi-sheet relationships, consider Laravel Excel or PhpSpreadsheet instead.
- What Laravel versions does FastExcel support, and is it compatible with PHP 8?
- FastExcel requires **Laravel 8+** and **PHP 8.0+**. It drops support for older PHP versions due to Spout v3’s requirements. If you’re on PHP 7.4 or below, you’ll need to upgrade or use Laravel Excel as an alternative.
- How do I customize CSV delimiters, encodings, or enclosures for imports?
- Use the `configureCsv()` method to set delimiters, enclosures, and encodings before importing. For example, `(new FastExcel)->configureCsv(';', '#', 'gbk')->import('file.csv')` handles German-style CSVs with semicolon delimiters and GBK encoding.
- Does FastExcel support multi-sheet Excel exports like PhpSpreadsheet?
- FastExcel supports **multiple sheets** via `SheetCollection`, but it’s less feature-rich than PhpSpreadsheet. For advanced Excel features like charts, formulas, or complex formatting, you’ll need to use PhpSpreadsheet or Laravel Excel instead.
- How can I handle large exports that exceed PHP’s memory limit?
- Use **chunked exports** with Eloquent’s `cursor()` method or yield rows in a callback. For example, `(new FastExcel(User::cursor()))->export('large_file.xlsx')` processes data in chunks, avoiding memory spikes. Monitor `memory_limit` in staging for edge cases.
- Is FastExcel suitable for background jobs or queued exports?
- Yes! FastExcel integrates seamlessly with Laravel Queues. Dispatch a job to handle large exports asynchronously, avoiding timeouts. Example: `ExportJob::dispatch(User::all())`, where the job uses `(new FastExcel($users))->export('path.xlsx')`.
- Can I map imported CSV rows directly to database inserts without loading everything into memory?
- Yes, use the import callback to process rows incrementally. For example, `(new FastExcel)->import('file.csv', function ($line) { User::create($line); })` inserts records row-by-row without loading the entire file into memory.
- What are the alternatives if FastExcel lacks advanced Excel features like formulas or charts?
- For advanced Excel features, use **Laravel Excel** (built on PhpSpreadsheet) or **PhpSpreadsheet directly**. FastExcel prioritizes speed and simplicity over feature richness, making it ideal for bulk data operations where formatting isn’t critical.
- How do I install and set up FastExcel in a Laravel project?
- Install via Composer: `composer require rap2hpoutre/fast-excel`. No additional configuration is needed. Use it directly in controllers or services, e.g., `(new FastExcel(User::all()))->download('users.xlsx')` for exports or `(new FastExcel)->import('file.xlsx')` for imports.