ajur-media / xlsx-writer
PHP Library to write XLSX files
0.9.9
2024-07-03 00:20 UTC
Requires (Dev)
- phpunit/phpunit: ^8.5 | ^9.5
- rector/rector: ^1.2
Replaces
This package is not auto-updated.
Last update: 2024-11-21 00:16:32 UTC
README
This is a fork of mk-j/php_xlsxwriter
compatible with PHP 7.2/3/4 and 8.0/1/2
Required PHP-ZIP extension, install like:
apt install libzip-dev php7.4-zip
Installation
composer require ajur-media/xlsx-writer
This library is designed to be lightweight, and have minimal memory usage.
It is designed to output an Excel compatible spreadsheet in (Office 2007+) xlsx format, with just basic features supported:
- supports PHP 7.4+ and 8.0+
- takes UTF-8 encoded input
- multiple worksheets
- supports currency/date/numeric cell formatting, simple formulas
- supports basic cell styling
- supports writing huge 100K+ row spreadsheets
Simple PHP CLI example:
$data = [ ['year','month','amount'], ['2003','1','220'], ['2003','2','153.5'], ]; $writer = new XLSXWriter(); $writer->writeSheet($data); $writer->writeToFile('output.xlsx');
Simple/Advanced Cell Formats:
$header = [ 'created'=>'date', 'product_id'=>'integer', 'quantity'=>'#,##0', 'amount'=>'price', 'description'=>'string', 'tax'=>'[$$-1009]#,##0.00;[RED]-[$$-1009]#,##0.00', ]; $data = [ ['2015-01-01',873,1,'44.00','misc','=D2*0.05'], ['2015-01-12',324,2,'88.00','none','=D3*0.05'], ]; $writer = new XLSXWriter(); $writer->writeSheetHeader('Sheet1', $header ); foreach($data as $row) $writer->writeSheetRow('Sheet1', $row ); $writer->writeToFile('example.xlsx');
50000 rows: (1.4s, 0MB memory usage)
$writer = new XLSXWriter(); $writer->writeSheetHeader('Sheet1', ['c1'=>'integer','c2'=>'integer','c3'=>'integer','c4'=>'integer'] ); for($i=0; $i<50000; $i++) { $writer->writeSheetRow('Sheet1', [$i, $i+1, $i+2, $i+3] ); } $writer->writeToFile('huge.xlsx'); echo '#'.floor((memory_get_peak_usage())/1024/1024)."MB"."\n";
Simple cell formats map to more advanced cell formats
Basic cell styles: