Import and Export Excel, CSV, & ODSOpen Files via Free PHP Library
Open Source PHP API that Enables Software Developers to Import and Export MS Excel Files. Learn Its Features, Benefits, and Code Examples to Handle Large Datasets Afficiently.
What is Fast-Excel?
Fast-Excel is a lightweight PHP package designed to simplify Excel and CSV import/export operations in Laravel applications. Built on top of OpenSpout, it focuses on speed, low memory usage, and developer-friendly syntax. Unlike heavier spreadsheet libraries, Fast-Excel is ideal for projects that need simple and efficient spreadsheet handling without unnecessary complexity. It supports exporting and importing XLSX, CSV, and ODS files while keeping memory consumption surprisingly low.
Fast-Excel is particularly useful for developers who need to process large Excel, CSV, or ODS files without running into memory limitations. Traditional libraries often load entire datasets into memory, but Fast-Excel uses streaming techniques to handle data efficiently. The library is widely used for exporting database records to spreadsheets, importing user data or reports, generating large reports dynamically, simplifying Excel handling in Laravel apps and so on. With its clean API and minimal configuration, Fast-Excel reduces development time while improving performance.
Getting Started with Fast-Excel
The recommended way to install Fast-Excel into your project is by using the composer. Please use the following command for a smooth installation
Install Fast-Excel via Composer
composer require rap2hpoutre/fast-excelYou can also clone the project with Git by running
Export Collections to Excel Files via PHP
Fast-Excel makes exporting collections or models to Excel incredibly simple. With just a few lines of code, you can generate .xlsx, .csv, or .ods files. This feature eliminates boilerplate code and speeds up development, especially for dashboards or reporting systems. The following example demonstrates how to Export data into MS Excel XLSX file using PHP code. The library converts a Laravel collection directly into an Excel file without requiring complex configurations.
How to Export Data into Excel XLSX File via PHP Library?
use Rap2hpoutre\FastExcel\FastExcel;
// Sample data
$list = collect([
['id' => 1, 'name' => 'Jane'],
['id' => 2, 'name' => 'John'],
]);
// Export to Excel
(new FastExcel($list))->export('users.xlsx');
Memory-Efficient Chunked Exports Using Generators
The open source Fast-Excel library has included support for low memory usage, and simple syntax for importing or exporting data. This is the flagship feature for handling "big data". Instead of loading 1 million users into an array, you use Laravel’s cursor() or a custom yield generator. The exporter processes each row one by one, writes it to the file, and discards it from memory. This keeps your memory usage constant (very low) regardless of whether you are exporting 100 rows or 10 million rows.
How to Export Specific Fields with Custom Headers inside PHP Apps?
return (new FastExcel(User::all()))->export('formatted_users.xlsx', function ($user) {
return [
'Full Name' => $user->firstname . ' ' . $user->lastname,
'Email Address' => $user->email,
'Member Since' => $user->created_at->format('Y-m-d'),
'Status' => $user->is_active ? 'Active' : 'Suspended'
];
});
Import Data Directly into Database
Instead of importing rows manually, Fast-Excel can process each row and directly insert it into your database. This is ideal for admin bulk uploads and has great benefits such as bulk database insertion, cleaner code, less manual processing, easy admin workflows and so on. This is particularly useful for HR systems, CRMs, and eCommerce platforms. Here is a useful example that shows how to import data into a database inside PHP applications.
How to Import Data Directly into a Database via PHP Library?
use Rap2hpoutre\FastExcel\FastExcel;
use App\Models\User;
(new FastExcel)->import('users.xlsx', function ($line) {
return User::create([
'name' => $line['Name'],
'email' => $line['Email'],
]);
});
Custom Column Mapping & Formatting via PHP
Database columns aren't always human-readable. The Fast-Excel library has included complete support for custom column or row mapping and formatting. This feature allows you to define exactly which attributes to export and reformat their values on the fly. Whether you need to uppercase a last name, combine first and last names, or rename ‘user_id’ to ‘Employee Identifier’, the closure gives you full control over the final output array.