Simple Excel
Simple Excel stats
- Downloads
- 2.8M
- Stars
- 990
- Open Issues
- 0
- Forks
- 110
Read and write simple Excel and CSV files
Spatie Simple Excel
The Spatie Simple Excel package provides a streamlined approach to reading and writing Excel and CSV files in Laravel, focusing on simplicity and minimal memory usage. Utilizing generators, it efficiently handles large files without substantial memory overhead, making it ideal for applications that require handling of extensive datasets.
Features
- Simple API: Easily read and write Excel and CSV files with a straightforward, intuitive API.
- Low Memory Usage: Uses generators to manage large files efficiently.
- LazyCollections Integration: Works with Laravel's LazyCollections for further memory efficiency.
- Flexible Reading Options: Supports reading files with or without headers and offers methods for custom headers and multiple sheets management.
- Robust Writing Capabilities: Includes features like streaming files to the browser, adding multiple rows simultaneously, and extensive styling and formatting options.
- Excel-Specific Features: Handles multiple sheets, custom styles, and formulas within cells.
Installation
Install the package via composer:
composer require spatie/simple-excel
Usage
Reading Files
You can read files by specifying the path, and the package automatically handles different file types based on the extension:
use Spatie\SimpleExcel\SimpleExcelReader; $rows = SimpleExcelReader::create($pathToCsv)->getRows();$rows->each(function(array $rowProperties) { // process each row});
Writing Files
Writing to a file is straightforward, with methods to add single or multiple rows:
use Spatie\SimpleExcel\SimpleExcelWriter; $writer = SimpleExcelWriter::create($pathToCsv) ->addRow(['first_name' => 'John', 'last_name' => 'Doe']) ->addRow(['first_name' => 'Jane', 'last_name' => 'Doe']);
Advanced Features
- Handling Multiple Sheets: Select sheets by name or index when reading and create new sheets when writing.
- Cell Formatting: Apply styles and formatting to cells specifically for Excel files.
- Streaming Downloads: Directly stream Excel files to the browser, ideal for exporting data on-the-fly.
- Custom Delimiters and Headers: Customize how data is read and interpreted, including support for files without headers.
Testing
Run the tests with:
composer test
Contributing
Contributions are welcome, and the package is open-source on GitHub. It also operates as "postcardware," where users are encouraged to send a postcard if they use the software in their production environment.
For a detailed guide on reading and writing capabilities, including working with large files and customizing headers, rows, and formatting, see the package's official documentation.