Lightweight Spreadsheets for Laravel
Last updated on by Paul Redmond
If you're looking for a lightweight package that can read and write spreadsheets, Chris Morrell's Linen package is a lightweight spreadsheet package for Laravel. This package is a wrapper for the openspout/openspout package which lets you read and write spreadsheets in a fast and scalable way.
Here are a few examples of how you can use the Linen package to read and write spreadsheets:
use Glhd\Linen\CsvReader;use Glhd\Linen\ExcelReader; $data = [ ['user_id' => 1, 'name' => 'Chris', 'nullable' => null, 'number' => 40.2], ['user_id' => 10, 'name' => 'Bogdan', 'nullable' => 'not null', 'number' => -37],]; // CSV$collection = CsvReader::from('basic.csv')->collect();$tempfile = CsvWriter::for($data)->writeToTemporaryFile(); // Excel$collection = ExcelReader::from('basic.xlsx')->collect();$tempfile = ExcelWriter::for($data)->writeToTemporaryFile();
Linen provides some conveniences on top of the Openspout package, such as using Laravel's LazyCollection class when reading spreadsheets. You can get started with this package by installing it via composer:
composer require glhd/linen
The readme and source code is available on GitHub at glhd/linen.