imtigger/oneexcel

PHP Excel read/write abstraction layer, support PhpSpreadSheet, LibXL, Spout and PHP fputcsv

v0.7.3 2019-05-07 13:42 UTC

This package is auto-updated.

Last update: 2024-12-08 02:14:41 UTC


README

Build Status Latest Stable Version Latest Unstable Version Total Downloads License

PHP Excel read/write abstraction layer, support PhpSpreadSheet, LibXL, Spout and PHP fputcsv/fgetcsv

Targets to simplify server compatibility issue between Excel libraries and performance issue in huge files.

Ideal for simple-formatted but huge spreadsheet files such as reporting.

Installation

Requirements

  • PHP >= 5.6.4
  • php_zip, php_xmlreader, php_simplexml enabled
  • (Recommended) LibXL installed & php_excel enabled

Composer

OneExcel can only be installed from Composer.

Run the following command:

$ composer require imtigger/oneexcel

Writer

Basic Usage

$excel = OneExcelWriterFactory::create()
        ->toFile('excel.xlsx')
        ->make();
        
$excel->writeCell(1, 0, 'Hello');
$excel->writeCell(2, 1, 'World');
$excel->writeCell(3, 2, 3.141592653, ColumnType::NUMERIC);
$excel->writeRow(4, ['One', 'Excel']);
$excel->writeCell(4, 2, 'Test');

$excel->output();
```Selection](driver.md)

### Advanced Usage

```php
$excel = OneExcelWriterFactory::create()
        ->fromFile('template.xlsx', Format::XLSX)
        ->toStream('excel.csv', Format::CSV)
        ->withDriver(Driver::SPOUT)
        ->make();
        
$excel->writeCell(1, 0, 'Hello');
$excel->writeCell(2, 1, 'World');
$excel->writeCell(3, 2, 3.141592653, ColumnType::NUMERIC);
$excel->writeRow(4, ['One', 'Excel']);
$excel->writeCell(4, 2, 'Test');

$excel->output();

Reader

(Version 0.6+)

$excel = OneExcelReaderFactory::create()
        ->fromFile('excel.xlsx')
        // ->withDriver(Driver::SPOUT)
        ->make();
        
foreach ($excel->row() as $row) {
    //
}

$excel->close();

Documents

Auto Driver Selection

Known Issues

  • Spout reader driver output empty rows as SINGLE column (Upstream problem?)
  • Spout do not support random read/write rows (Upstream limitation, Won't fix)
  • Spout do not support formula (Upstream limitation, Won't fix)
  • fputcsv driver ignores all ColumnType::* (File-type limitation, Won't fix)