- How do I install rap2hpoutre/fast-excel in a Laravel app?
- Install the package with Composer by running composer require rap2hpoutre/fast-excel. Laravel's package discovery registers the service provider and FastExcel facade automatically. You can then use the FastExcel class, the FastExcel facade, or the fastexcel() helper without publishing configuration.
- Which Laravel and PHP versions does fast-excel support?
- Fast Excel is optimized for modern Laravel applications and requires PHP 8.0 or newer. It integrates with Laravel 9+ and uses Eloquent, Collections, and the service container. Older PHP 7.x projects should stay on legacy packages or upgrade before adopting it.
- How does fast-excel handle very large exports without using too much memory?
- It is built on Spout v3, which streams rows instead of loading the entire workbook into memory. The chunked export API with yield lets you process large datasets in batches. This makes exports of 1M+ rows feasible with a small memory footprint, but you should still benchmark and monitor memory in staging.
- How do I export an Eloquent model or collection to Excel or CSV?
- Pass a model query result, Eloquent collection, or Laravel collection into the FastExcel constructor, then call export with a file path. For example, (new FastExcel(User::all()))->export('users.xlsx') writes an XLSX file. The same API supports ODS and CSV by changing the file extension. From a controller you can return the download response using the package's download method.
- Can I choose which columns are exported and rename their headers?
- Yes, pass a callback as the second argument to export and return an associative array of column names to values. For example, return ['Email' => $user->email, 'First Name' => $user->firstname]. You can also hide helper columns with hideColumnsPrefixedWith so callback-only values do not appear in the file.
- How do I import an Excel or CSV file and insert rows into the database?
- Call import on a FastExcel instance to read the file into a Laravel collection. You can then transform rows or use the create method to insert them directly into a model's table. This import plus create pattern is useful for bulk seeding and simple ETL workflows.
- Can fast-excel export CSV files with custom delimiters or encodings?
- Yes, CSV output can be configured with options such as delimiters and encodings to support localized deployments. The assessment notes that locale-specific encodings like gbk should be validated in QA. Provide sensible fallback defaults for environments with different CSV expectations.
- How is fast-excel different from Laravel Excel or PhpSpreadsheet?
- Fast Excel focuses on speed and low memory use through Spout streaming, while Laravel Excel and PhpSpreadsheet offer richer Excel features. Basic exports and imports can often be replaced with fewer than 5 percent code changes. Choose Fast Excel for simple high-volume files and Laravel Excel when you need advanced formatting or templates.
- Does fast-excel support multi-sheet workbooks, charts, formulas, or merged cells?
- No, it is intentionally limited to straightforward single-sheet imports and exports. It does not provide charts, formulas, merged cells, or complex Excel templates. Multi-sheet relationships require manual mapping, so use Laravel Excel if those features are mandatory.
- Is rap2hpoutre/fast-excel actively maintained and safe for production?
- The package is MIT licensed and actively developed, with Spout v3 as its underlying engine. It is production-ready for simple, high-volume Excel and CSV operations when you pin versions with composer.lock and test upgrades. Monitor Spout major releases and benchmark performance against your baseline after integration.