CakePHP excel generator using PHPExcel library

Installs: 2 659

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 1

Forks: 2

Open Issues: 0


v1.1.2 2015-02-23 18:08 UTC

This package is not auto-updated.

Last update: 2020-05-25 11:50:02 UTC


A plugin to generate Excel files with CakePHP. Uses CakePHP view files to generate them (with PHPExcel_IOFactory class from PHPExcel).


  • PHP 5.2.8
  • CakePHP 2.1+
  • PHPExcel
  • Composer


Add to your composer.json file (maraya/cake-php-excel)

"require": {
	"maraya/cake-php-excel": "1.1.*"
"config": {
	"vendor-dir": "Vendor/"
"extra": {
    "installer-paths": {
        "Plugin/CakePHPExcel": ["maraya/cake-php-excel"]

And run

composer update


In app/Config/bootstrap.php add:

		'routes' => true

Add the RequestHandler component to AppController, and map Excel extensions to the CakePHPExcel plugin

'RequestHandler' => array(
	'viewClassMap' => array(
		'xls' => 'CakeExcel.Excel',
		'xlsx' => 'CakeExcel.Excel'

Create Layouts/xls/default.ctp (in this example the charset is UTF-8)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<?php echo $this->fetch('content'); ?>

Place the view templates in a xls subdir, for example: app/View/Reports/xls/clients.ctp

<table width="100%" border="1">

And in your controller:

class ReportsController extends AppController {
    public function clients() {
		$this->excelConfig =  array(
			'filename' => 'clients.xlsx'

Call the URL

If you want to download Excel5 format, change the URL extension from xlsx to xls.

Inside your view file you can write HTML code. Please see the PHPExcel documentation for a guide on how to use PHPExcel.