Download the PHP package datasuite/laravel-exporter without Composer
On this page you can find all versions of the php package datasuite/laravel-exporter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-exporter
Laravel Exporter
A fluent, memory-efficient data export package for Laravel supporting CSV, Excel, and JSON formats with rich formatting capabilities.
Features
- 🚀 Fluent API - Clean, chainable methods for building exports
- 💾 Memory Efficient - Uses generators and chunking for large datasets
- 📊 Multiple Formats - CSV, Excel (XLSX/XML), and JSON support
- 🔄 Flexible Data Sources - Works with Eloquent queries, Collections, and arrays
- 🎯 Column Types - Amount, Date, Percentage, Quantity with proper formatting
- 🌍 Multi-Locale Support - Configurable number formats for any country (US, UK, EU, India, Japan, China, etc.)
- 🎨 Conditional Coloring - Configurable colors for positive/negative amounts (optional)
- 📋 Report Headers - Company name, title, date range, generated by (optional)
- ➕ Totals & Subtotals - Automatic calculation of column totals (optional)
- 🔧 Customizable - Transform rows, set headers, and configure format options
- 📦 Zero Dependencies - Excel export works without external libraries (optional OpenSpout support)
Installation
The package will automatically register its service provider via Laravel's package auto-discovery.
Publish Configuration (Optional)
Basic Usage
Using the Facade
Using the Class Directly
Data Sources
The exporter supports multiple data sources:
Export Formats
CSV Export
Excel Export
Note: For native XLSX support, install OpenSpout:
composer require openspout/openspoutWithout OpenSpout, exports will use Excel-compatible XML format.
Excel Export with Column Types
Define column types for proper formatting and optional conditional coloring:
Column Types Available
| Type | Method | Description | Excel Format |
|---|---|---|---|
| String | ->string() |
Plain text | General |
| Integer | ->integer() |
Whole numbers | #,##0 |
| Amount | ->amount() |
Currency with optional conditional coloring | #,##0.00 (locale-based) |
| Amount Plain | ->amountPlain() |
Currency without coloring | #,##0.00 |
| Percentage | ->percentage() |
Percentage values | 0.00% |
| Date | ->date() |
Date values | DD-MMM-YYYY |
| DateTime | ->datetime() |
Date and time | DD-MMM-YYYY HH:MM:SS |
| Boolean | ->boolean() |
Yes/No values | General |
| Quantity | ->quantity() |
Numeric quantities | #,##0.00 |
Report Headers (Optional)
Add professional headers to your exports when needed:
Totals Row (Optional)
Automatically calculate and add totals when needed:
Multi-Locale Support & Conditional Coloring
Configure locale-specific number formatting for any country:
Supported Locales (Configurable)
| Locale | Country | Number Format | Currency |
|---|---|---|---|
en_US |
United States | 1,234,567.00 | $ |
en_GB |
United Kingdom | 1,234,567.00 | £ |
en_IN |
India | 12,34,567.00 | ₹ |
de_DE |
Germany | 1.234.567,00 | € |
fr_FR |
France | 1 234 567,00 | € |
ja_JP |
Japan | 1,234,567 | ¥ |
zh_CN |
China | 1,234,567.00 | ¥ |
Add more locales in config/exporter.php.
JSON Export
Column Selection
Simple Columns
Column Aliases
Nested Columns (Dot Notation)
Custom Headers
Row Transformation
Transform each row before export:
Output Methods
Save to File
Download Response
Stream Response (Memory Efficient)
Get as String
Using the Exportable Trait
Add export functionality directly to your models:
Then use it like this:
Controller Example
Memory Optimization
For large datasets, the package automatically uses:
- Generators - Data is processed one row at a time
- Lazy Collections - Eloquent queries use
lazy()for memory efficiency - Chunking - Configure chunk size for optimal performance
Configuration
Publish the config file to customize defaults:
Requirements
- PHP 8.1+
- Laravel 10.x or 11.x
Optional Dependencies
openspout/openspout- For native XLSX file supportphpoffice/phpspreadsheet- For advanced Excel features (formulas, conditional formatting, cell merging)
Maatwebsite Excel-Style Exports (NEW!)
If you're familiar with Maatwebsite Excel, you'll feel right at home! We now support the same interface-based Concerns pattern for cleaner, reusable export classes.
Quick Start
Creating an Export Class
Simple Export (FromCollection)
Query-Based Export (FromQuery) - Memory Efficient
Full-Featured Export with Styles
Available Concerns
| Concern | Description |
|---|---|
FromCollection |
Use a Laravel Collection as data source |
FromQuery |
Use an Eloquent Builder (memory efficient with cursor) |
FromArray |
Use a plain PHP array as data source |
FromGenerator |
Use a Generator for custom iteration |
WithHeadings |
Add column headers to export |
WithMapping |
Transform each row before exporting |
WithChunkReading |
Process data in chunks for very large datasets |
WithColumnFormatting |
Apply number/date formats (requires PhpSpreadsheet) |
WithColumnWidths |
Set fixed column widths |
WithStyles |
Apply cell styles (requires PhpSpreadsheet) |
ShouldAutoSize |
Auto-size columns to fit content |
WithTitle |
Set worksheet title |
WithMultipleSheets |
Export multiple sheets in one file |
WithTotals |
Add a totals/summary row |
WithReportHeader |
Add report header block |
WithColumnDefinitions |
Use column type definitions |
WithConditionalColoring |
Enable conditional coloring |
WithFreezeRow |
Freeze header row |
WithAutoFilter |
Add auto-filter dropdown |
WithEvents |
Register event hooks |
Chunked Reading for Large Datasets
For very large datasets (100K+ rows), use WithChunkReading to process data in batches:
| Memory Comparison: | Method | Memory Usage | Best For |
|---|---|---|---|
FromCollection |
High (loads all) | Small datasets (<1K rows) | |
FromQuery (cursor) |
Medium | Medium datasets (1K-50K rows) | |
FromQuery + WithChunkReading |
Low | Large datasets (50K+ rows) |
Using the Exportable Trait
The Exportable trait adds convenient methods to your export class:
Multiple Sheets
Comparison: Fluent API vs Concerns
Both styles are supported! Choose what works best for your use case:
| Fluent API | Concerns Pattern |
|---|---|
| Quick, inline exports | Reusable export classes |
| Good for simple exports | Better for complex exports |
| Less boilerplate | More organized |
Exporter::make()->from($data) |
Excel::download(new Export) |
Importing Data (Maatwebsite-Style)
The package also supports importing data from CSV, Excel, and JSON files using the same Concerns pattern as Maatwebsite Excel.
Basic Import
Creating an Import Class
Import Concerns
| Concern | Description |
|---|---|
ToModel |
Convert each row to an Eloquent model |
ToCollection |
Process all rows as a Collection |
ToArray |
Process all rows as an array |
OnEachRow |
Process each row individually |
WithHeadingRow |
Use first row as array keys |
WithValidation |
Validate each row |
WithBatchInserts |
Insert models in batches |
WithUpserts |
Update existing or create new |
WithChunkReading |
Read file in chunks |
SkipsOnError |
Skip rows that cause errors |
SkipsOnFailure |
Skip rows that fail validation |
WithStartRow |
Start reading from specific row |
WithLimit |
Limit number of rows |
WithColumnLimit |
Limit columns to read |
WithCalculatedFormulas |
Get formula results |
WithMappedCells |
Read specific cells |
WithMultipleSheets |
Handle multiple sheets |
Import with Upserts (Update or Create)
Handling Validation Failures
ToCollection Import
Converting to Array/Collection
Multi-Sheet Import
Using the Importable Trait
Import Result
Supported File Formats
| Format | Extension | Reader |
|---|---|---|
| CSV | .csv, .txt, .tsv | Native (streaming) |
| Excel | .xlsx, .xls | OpenSpout (streaming) |
| JSON | .json | Native |
License
MIT License
All versions of laravel-exporter with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
symfony/http-foundation Version ^6.0|^7.0