slam / php-excel
Old faster PHPExcel
Fund package maintenance!
Slamdunk
paypal.me/filippotessarotto
Requires
- php: >=8.0
- ext-iconv: *
- ext-mbstring: *
Requires (Dev)
- malukenho/mcbumpface: ^1.1.5
- mikey179/vfsstream: ^1.6.10
- phpoffice/phpspreadsheet: ^1.20.0
- phpstan/phpstan: ^1.2.0
- phpstan/phpstan-phpunit: ^1.0.0
- phpunit/phpunit: ^9.5.10
- slam/php-cs-fixer-extensions: ^3.1.0
- slam/php-debug-r: ^1.7.0
- slam/phpstan-extensions: ^6.0.0
README
Slam PHPExcel old&faster
This package is NOT intended to be complete and flexible, but to be fast.
PHPOffice/PHPExcel and PHPOffice/PhpSpreadsheet are great libraries, but abstract everything in memory before writing to the disk. This is extremely inefficent and slow if you need to write a giant XLS with thousands rows and hundreds columns.
Based on Spreadsheet_Excel_Writer v0.9.3, which can be found active on Github. This is not a fork: I copied it and adapted to work with PHP 7.1 and applied some coding standard fixes and some Scrutinizer patches.
Installation
composer require slam/php-excel
Usage
From version 4 the code is split in two parts:
Slam\Excel\Pear
namespace, the original Pear codeSlam\Excel\Helper
namespace, an helper to apply a trivial style on a Table structure:
use Slam\Excel\Helper as ExcelHelper; require __DIR__ . '/vendor/autoload.php'; // Being an Iterator, the data can be any dinamically generated content // for example a PDOStatement set on unbuffered query $users = new ArrayIterator([ [ 'column_1' => 'John', 'column_2' => '123.45', 'column_3' => '2017-05-08', ], [ 'column_1' => 'Mary', 'column_2' => '4321.09', 'column_3' => '2018-05-08', ], ]); $columnCollection = new ExcelHelper\ColumnCollection([ new ExcelHelper\Column('column_1', 'User', 10, new ExcelHelper\CellStyle\Text()), new ExcelHelper\Column('column_2', 'Amount', 15, new ExcelHelper\CellStyle\Amount()), new ExcelHelper\Column('column_3', 'Date', 15, new ExcelHelper\CellStyle\Date()), ]); $filename = sprintf('%s/my_excel_%s.xls', __DIR__, uniqid()); $phpExcel = new ExcelHelper\TableWorkbook($filename); $worksheet = $phpExcel->addWorksheet('My Users'); $table = new ExcelHelper\Table($worksheet, 0, 0, 'My Heading', $users); $table->setColumnCollection($columnCollection); $phpExcel->writeTable($table); $phpExcel->close();
Result: