data33/phpexcel-wrapper

A quick and easy wrapper to make excel exports easier

dev-master 2015-08-05 07:18 UTC

This package is auto-updated.

Last update: 2024-10-23 18:19:26 UTC


README

A quick and easy wrapper to make excel exports easier

Example usage

$excel = new Data33\ExcelWrapper\ExcelWrapper();

$excel->setTitle('My first excel file')
		->addRow(['Country', 'Capital'], 'header')
		->addRow(['Sweden', 'Stockholm'])
		->addRow(['Norway', 'Oslo'])
		->save('countries.xlsx');

To style specific cells:

$excel->setTitle('My first excel file')
		->addRow(['Country', 'Capital'], 'header')
		->addRow([['Europe', 'header']])
		->addRow(['Sweden', 'Stockholm'])
		->addRow([['Africa', 'header']])
		->addRow(['Tunisia', 'Tunis'])
		->save('countries.xlsx');

To add custom styles we can give the wrapper PHPExcel style arrays:

Data33\ExcelWrapper\ExcelStyle::setStyle('red', [
	'font' => [
		'size' => 10,
		'name' => 'Arial',
		'color' => [
			'rgb' => 'ff0000'
		]
	]
]);

$excel->setTitle('My first excel file')
		->addRow(['Country', 'Capital'], 'header')
		->addRow(['Sweden', ['Stockholm', 'red']])
		->addRow(['Norway', ['Oslo', 'red']])
		->save('countries.xlsx');

To output directly to browser for download:

$excel->setTitle('My first excel file')
		->addRow(['Country', 'Capital'], 'header')
		->addRow(['Sweden', 'Stockholm'])
		->addRow(['Norway', 'Oslo'])
		->outputToBrowser('countries.xlsx');