Fast Excel has changed substantially since Laravel News covered the package in 2020. That article covered v2.2-era collection exports, browser downloads, and multi-sheet workbooks. Fast Excel 5 now includes lazy imports, controls for splitting spreadsheet work across jobs, sheet and column selection, and safer handling of user-controlled export values.
The recent releases make Fast Excel more useful for large operational imports, not only simple report downloads. The package still uses OpenSpout rather than trying to expose every feature in the Excel file format, which keeps it focused on reading and writing rows with low memory use.
importLazy()reads rows through aLazyCollectionheaderRow(),startRow(), andlimitRows()support chunked importssheet()andonlyColumns()select the data an import needsescapeFormulas()writes user-controlled formula-like values as text
Lazy imports for large files
import() returns a collection containing every imported row. For a large upload, that can use more memory than the PHP process has available. importLazy() yields rows through a LazyCollection, so an application can batch the database work without retaining the full file:
use App\Models\Contact;use Illuminate\Support\LazyCollection;use Rap2hpoutre\FastExcel\FastExcel; (new FastExcel)->importLazy('contacts.xlsx') ->chunk(1_000) ->each(function (LazyCollection $contacts) { Contact::insert($contacts->all()); });
Fast Excel 5.12 introduced importLazy() alongside streaming export changes. The package's own benchmark compares a generator export with a materialised collection, and the repository includes the benchmark script. For an import that arrives as CSV, the same approach can replace some of the manual parsing used for a large CSV upload.
Chunked imports with stable headings
The newer import controls help when one queued job should process a portion of a spreadsheet. headerRow() reads keys from the actual heading row, while startRow() selects where the current chunk begins and limitRows() caps its size:
use Rap2hpoutre\FastExcel\FastExcel; $rows = (new FastExcel) ->headerRow(1) ->startRow(2 + ($page * 1_000)) ->limitRows(1_000) ->import('orders.xlsx');
Before Fast Excel 5.17, startRow() also treated the selected row as the headings. A later chunk could therefore use a data row as its keys. headerRow() separates those positions and leaves the old startRow() behaviour unchanged unless you opt in. #418 added the method.
Selecting sheets and columns
The package can select a sheet by name and keep only the columns an import needs:
use Rap2hpoutre\FastExcel\FastExcel; $orders = (new FastExcel) ->sheet('Orders') ->onlyColumns(['A', 'B', 'H']) ->import('customer-export.xlsx');
onlyColumns() accepts column letters or one-based positions. It avoids returning empty fields from sheets where formatting was applied far beyond the real data. limitColumns() is available when an import needs every column up to a given position instead. These options arrived in Fast Excel 5.16, which also added the option to pass an OpenSpout cell instance as an export value. #419
Escaping spreadsheet formulas
Spreadsheet applications can treat values starting with =, +, -, or @ as formulas. When those values come from an uploaded CSV or a database field controlled by users, a report export can turn plain text into a formula when somebody opens it.
Call escapeFormulas() before exporting to write those values as text:
use Rap2hpoutre\FastExcel\FastExcel; (new FastExcel($rows)) ->escapeFormulas() ->export('orders.xlsx');
Fast Excel 5.17 added the method in #411.
Compatibility
Fast Excel 5 requires PHP 8.0 or later and Laravel 6 or later. The current release supports Laravel 6 through 13 and uses OpenSpout 4. Applications still on the Laravel 5 or PHP 7 baseline supported by Fast Excel 2 need to plan the dependency upgrade separately.
The major-version history includes a move from box/spout to openspout/openspout, plus a PHP 8 requirement in Fast Excel 5. Projects that use an earlier Fast Excel release should check those dependency changes before updating.
Installation
Install Fast Excel with Composer:
composer require rap2hpoutre/fast-excel