Easy Excel: A PHP Library for Efficient Low‑Memory Excel Read/Write
Easy Excel is a PHP library built on openspout that enables fast, low‑memory reading and writing of xlsx, csv, and ods files, providing installation steps, environment requirements, and code examples for exporting, importing, and handling Excel data in backend applications.
Easy Excelis a PHP library built on openspout/openspout that provides fast, low‑memory Excel read/write capabilities for xlsx, csv, and ods files.
Environment
PHP >= 7.2
php_zip extension
php_xmlreader extension
openspout/openspout >= 3.0
league/flysystem >= 1.0
Installation composer require yzh52521/easy-excel Quick start – Export
Download example:
use Dcat\EasyExcel\Excel;
$array = [
['id'=>1, 'name'=>'Brakus', 'email'=>'[email protected]', 'created_at'=>'...'],
// ...
];
$headings = ['id'=>'ID', 'name'=>'名称', 'email'=>'邮箱'];
Excel::export($array)->headings($headings)->download('users.xlsx');
Excel::export($array)->headings($headings)->download('users.csv');
Excel::export($array)->headings($headings)->download('users.ods');Save to server:
use Dcat\EasyExcel\Excel;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
Excel::export($array)->store('/tmp/users.xlsx');
$adapter = new Local(__DIR__);
$filesystem = new Filesystem($adapter);
Excel::export($array)->disk($filesystem)->store('users.xlsx');Quick start – Import
Read all sheets:
use Dcat\EasyExcel\Excel;
$headings = ['id','name','email'];
$allSheets = Excel::import('/tmp/users.xlsx')
->headings($headings)
->toArray();Iterate sheets with chunking:
Excel::import('/tmp/users.xlsx')
->each(function (SheetInterface $sheet) {
$sheetName = $sheet->getName();
$sheetIndex = $sheet->getIndex();
$isActive = $sheet->isActive();
$sheet->chunk(100, function (SheetCollection $collection) {
$chunkArray = $collection->toArray();
// process $chunkArray
});
});Access specific sheet content:
$firstSheet = Excel::import('/tmp/users.xlsx')->first()->toArray();
$activeSheet = Excel::import('/tmp/users.xlsx')->active()->toArray();
$sheetByName = Excel::import('/tmp/users.xlsx')->sheet('Sheet1')->toArray();
$sheetByIndex = Excel::import('/tmp/users.xlsx')->sheet(0)->toArray();For more import features, refer to the official documentation.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
