Skip to content

About

Streaming Excel (.xlsx) and CSV exporter for PHP 8.2+ with native CWE-1236 Formula Injection defense (<16MB RAM)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LiteExport 📊

Latest Version PHP Version License: MIT

Ultra-fast, memory-efficient streaming Excel (.xlsx) and CSV exporter in pure PHP 8.2+ with zero external dependencies (< 16MB RAM for 100K+ rows).

PHP 8.2+ License: MIT Zero External Dependencies Tests


⚡ Why LiteExport?

Standard PHP spreadsheet libraries (such as phpoffice/phpspreadsheet) allocate heavyweight in-memory cell models, consuming 80MB to 300MB+ of RAM for large exports and frequently causing Out-Of-Memory (OOM) crashes in Docker containers and web workers.

LiteExport bypasses in-memory DOM allocations completely:

  • Streams row-by-row directly into compressed OpenXML parts on disk using PHP Generators.
  • Includes a pure PHP OpenXML Zip packager (SimpleZip) utilizing native zlib—runs without even requiring ext-zip.
  • Memory usage stays strictly under 16MB regardless of dataset size (1,000 or 500,000 rows).
  • Integrates seamlessly with LiteORM::cursor() for end-to-end $O(1)$ memory database exports.
  • CWE-1236 Formula Injection Mitigation: Automatically sanitizes dangerous spreadsheet trigger prefixes (=, +, -, @, \t, \r) in CSV files.

📦 Installation

Option 1: Standard Composer (via Packagist)

composer require kzxl/lite-export

Option 2: Direct from Git Repository (VCS)

To pull directly from the official GitHub repository without waiting for Packagist synchronization, add the VCS repository to your project's composer.json:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/kzxl/LiteExport.git"
        }
    ],
    "require": {
        "kzxl/lite-export": "^1.1.0"
    }
}

Or configure via CLI:

composer config repositories.lite-export vcs https://github.com/kzxl/LiteExport.git
composer require kzxl/lite-export:^1.1.0

Option 3: Local Path Repository (Monorepo / Development)

For local development where changes should reflect immediately via symlink:

{
    "repositories": [
        {
            "type": "path",
            "url": "../libs/LiteExport",
            "options": {
                "symlink": true
            }
        }
    ],
    "require": {
        "kzxl/lite-export": "@dev"
    }
}

🚀 Usage Guide

1. High-Performance Excel (.xlsx) Export

use LiteExport\Exporter;

// Export from array
$data = [
    ['id' => 1, 'name' => 'Alice Johnson', 'price' => 150.00],
    ['id' => 2, 'name' => 'Bob Smith', 'price' => 320.50],
];

Exporter::xlsx($data, '/path/to/report.xlsx', sheetName: 'Customers');

// Export from LiteORM database cursor with O(1) memory!
$usersCursor = $em->query(User::class)->cursor(); // Yields one row at a time
Exporter::xlsx($usersCursor, '/path/to/large_users_export.xlsx');

2. High-Performance CSV Export (with UTF-8 BOM for Excel)

use LiteExport\Exporter;

// Auto-prepends UTF-8 BOM so Microsoft Excel opens Vietnamese / Unicode without errors
Exporter::csv($usersCursor, '/path/to/export.csv');

// Or export directly to string
$csvString = Exporter::csv($data);

🧪 Testing

composer test
# or
./vendor/bin/phpunit

📄 License

MIT License — see LICENSE for details.
Architected by Phong Vo (kzxl).

About

Streaming Excel (.xlsx) and CSV exporter for PHP 8.2+ with native CWE-1236 Formula Injection defense (<16MB RAM)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages