Download the PHP package moshontong/excel-export-streamer without Composer
On this page you can find all versions of the php package moshontong/excel-export-streamer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download moshontong/excel-export-streamer
More information about moshontong/excel-export-streamer
Files in moshontong/excel-export-streamer
Package excel-export-streamer
Short Description A memory-efficient Laravel package for streaming Excel exports without holding data in memory
License MIT
Homepage https://github.com/moshOntong-IT/mosh-excel-export-streamer
Informations about the package excel-export-streamer
Mosh Excel Export Streamer
A memory-efficient Laravel package for exporting Excel files without running into memory limits. Features true streaming for CSV exports and memory-optimized file generation for XLSX exports. Perfect for exporting millions of records safely and efficiently.
Features
- Memory Efficient: Uses different optimized approaches per format - true streaming for CSV, temporary files for XLSX
- Flexible Data Sources: Works with Eloquent queries, arrays, custom data providers, and data mapper callbacks
- Multiple Formats: Supports CSV and XLSX formats
- Multi-Sheet Support: Create XLSX files with multiple worksheets
- Chunked Processing: Processes data in configurable chunks with smart optimization
- Framework Agnostic: Use in any controller or service
- Comprehensive Logging: Built-in logging for debugging and monitoring
- Performance Optimized: Automatic query complexity detection and chunk size optimization
- No External Dependencies: Built with native PHP and Laravel
How It Works
The package uses different approaches optimized for each export format:
CSV Exports 🚀
- True Streaming: Data streams directly from database to browser chunk-by-chunk
- Immediate Download: Download dialog appears instantly as data flows
- Memory Efficient: Never holds the full dataset in memory
- Best For: Large datasets where immediate streaming is priority
XLSX Exports 📊
- Generate + Stream: Creates complete XLSX file using temporary storage, then streams the file
- Excel Compatible: Produces valid ZIP-structured XLSX files that Excel opens correctly
- Memory Optimized: Uses chunked processing and temporary files to minimize memory usage
- Best For: Datasets requiring Excel compatibility, multi-sheet functionality
💡 Pro Tip: Choose CSV for maximum performance and true streaming. Choose XLSX when Excel compatibility and formatting are required.
Installation
Install via Composer:
The package will auto-register via Laravel's package discovery.
Publish Configuration (Optional)
Basic Usage
1. Inject the Service
2. Export from Eloquent Query
3. Export from Array
4. Advanced Usage with Custom Data Provider
5. Data Mapper for Complex Transformations
Transform data row-by-row during streaming with custom callbacks. Perfect for complex calculations, relationship data, and custom formatting:
Data Mapper Benefits:
- 🚀 Memory Efficient: Transforms data row-by-row during streaming (no memory bloat)
- 🔧 Flexible: Handle complex calculations, relationships, and custom formatting
- 🛡️ Error Resilient: Automatic fallback to default column extraction on mapper errors
- 🔄 Backward Compatible: Optional parameter, existing code continues working
Advanced Example - Financial Report:
6. Multi-Sheet XLSX Export
Create XLSX files with multiple worksheets in a single file:
Basic Multi-Sheet Export
Advanced Multi-Sheet with Data Mappers 🎯
Combine multi-sheet functionality with data transformation for powerful business reports:
Multi-Sheet Data Mapper Features:
- 🎯 Per-Sheet Transformation: Each sheet can have its own data mapper with unique business logic
- 📊 Mixed Sheet Types: Combine sheets with data mappers and basic column exports in the same file
- 🚀 Memory Efficient: Data mappers work seamlessly with chunked processing for large datasets
- 🛡️ Error Resilient: Automatic fallback to column extraction if mapper fails on any sheet
- ⚙️ Flexible Options: Custom chunk sizes and options per sheet
Logging
The package includes comprehensive logging capabilities:
Log entries include:
- Export start/completion with record counts
- Memory usage and performance metrics
- Execution time warnings
- Query complexity detection
- Error tracking with context
Configuration
The package comes with sensible defaults, but you can customize everything:
Model Integration
Make your Eloquent models exportable:
Frontend Integration Examples
Vanilla JavaScript
Vue.js Example
Performance Tips
Format Selection
- Choose CSV for True Streaming: For maximum performance and immediate download, use CSV format
- Use XLSX When Excel Compatibility Required: Accept the trade-off of file generation for proper Excel support
- Consider Dataset Size: CSV handles millions of records with constant memory usage; XLSX uses temporary files
Optimization Strategies
- Optimize Chunk Size: Start with 1000 for XLSX, 2000+ for CSV; adjust based on your data complexity
- Use Specific Columns: Only select columns you need - especially important for XLSX temporary file size
- Add Database Indexes: Ensure your queries are optimized for the columns you're ordering by
- Use Data Mappers for Complex Logic: Instead of pre-processing data, use mapper callbacks for transformations during streaming
- Monitor Memory Usage: Enable memory warnings in config to track usage patterns
- Enable Query Log Disabling: Set
disable_query_logto true in config for better performance
XLSX-Specific Tips
- Temporary Directory: Configure fast storage (SSD) for
temp_dirin XLSX config - Cleanup Monitoring: Large XLSX exports create temporary files - ensure adequate disk space
Error Handling
Testing
Requirements
- PHP 8.1+
- Laravel 10.0+ or 11.0+
License
MIT License. See LICENSE file for details.
Contributing
Pull requests are welcome! Please ensure tests pass and follow PSR-12 coding standards.
Support
- Create an issue on GitHub for bug reports
- Check existing issues before creating new ones
- Provide minimal reproduction examples