PHPackages                             chcnetconsulting/cakephp-excel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. chcnetconsulting/cakephp-excel

ActiveCakephp-plugin

chcnetconsulting/cakephp-excel
==============================

Robotusers CakePHP Excel plugin

0.6.0(7y ago)09[1 PRs](https://github.com/chcnetconsulting/cakephp-excel/pulls)MITPHPPHP &gt;=5.6

Since Mar 22Pushed 5y agoCompare

[ Source](https://github.com/chcnetconsulting/cakephp-excel)[ Packagist](https://packagist.org/packages/chcnetconsulting/cakephp-excel)[ Docs](https://github.com/robotusers/cakephp-excel)[ RSS](/packages/chcnetconsulting-cakephp-excel/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (11)Used By (0)

CakePHP Excel plugin
====================

[](#cakephp-excel-plugin)

Update for CakePHP 4.x

[![Latest Stable Version](https://camo.githubusercontent.com/0358f6376ac9e2075c76ae4e4d3739619415c001dbb8a23fe57ab41ef59f890b/68747470733a2f2f706f7365722e707567782e6f72672f726f626f7475736572732f63616b657068702d657863656c2f762f737461626c65)](https://packagist.org/packages/robotusers/cakephp-excel)[![Total Downloads](https://camo.githubusercontent.com/16e3af62e08da02701cd52c724bf1ebc1030b205af2d2ee4a19430893173cc3f/68747470733a2f2f706f7365722e707567782e6f72672f726f626f7475736572732f63616b657068702d657863656c2f646f776e6c6f616473)](https://packagist.org/packages/robotusers/cakephp-excel)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/250ea8f4d6aa48c70d31c64e604d70b77d401ce95018c13758f1c7c06623fcb7/68747470733a2f2f7472617669732d63692e6f72672f726f626f7475736572732f63616b657068702d657863656c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/robotusers/cakephp-excel)[![codecov](https://camo.githubusercontent.com/419245d87e3ce247c2832945a0e3d8ba935534da7166f417d809ebbdec305005/68747470733a2f2f636f6465636f762e696f2f67682f726f626f7475736572732f63616b657068702d657863656c2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/robotusers/cakephp-excel)

CakePHP Excel plugin allows for spreadsheet files manipulation with the power of CakePHP ORM. This plugin is build using [PHPSpreadsheet](https://github.com/PHPOffice/PHPSpreadsheet) library and can work with multiple types of spreadsheet files (excel, csv etc).

**NOTE:**CakePHP Excel plugin versions 0.4.0 and lower used now abandoned [PHPExcel](https://github.com/PHPOffice/PHPExcel) library.

Installation
------------

[](#installation)

```
composer require robotusers/cakephp-excel

```

CakePHP 3.6+

```
//Application.php

public function bootstrap()
{
    ...
    $this->addPlugin('Robotusers/Excel');
}
```

CakePHP 3.5 and lower:

```
bin/cake plugin load Robotusers/Excel -b

```

Using the plugin
----------------

[](#using-the-plugin)

Excel plugin lets you manipulate spreadsheet files multiple ways. The simplest use case is to load your spreadhseet data into CakePHP ORM table.

For example we are loading an excel file that contains some record data.

ABC1Led ZeppelinLed Zeppelin II19692Deep PurpleMachine Head19723Pink FloydWish You Were Here1975```
use Robotusers/Excel/Registry;

$registry = Registry::instance();
$table = $registry->get('path/to/records.xlsx', 'Albums');
```

Spreadsheet data is now loaded into CakePHP ORM table.

```
$row = $table->find()->first()->toArray();

//this is how a simple row looks like:
[
    '_row' => 1,
    'A' => 'Led Zeppelin',
    'B' => 'Led Zeppelin II',
    'C' => '1969'
]
```

Each column is represented as a property. Values are `string` by default.

You may also map columns to custom properties and types.

```
use Robotusers/Excel/Registry;

$registry = Registry::instance();
$table = $registry->get('path/to/records.xlsx', 'Albums', [
    'primaryKey' => 'id',
    'columnMap' => [
        'A' => 'band',
        'B' => 'album',
        'C' => 'year'
    ],
    'columnTypeMap' => [
        'C' => 'date'
    ]
]);
```

Spreadsheet data is now loaded into CakePHP ORM with custom properties and types.

```
$row = $table->find()->first()->toArray();

//this is how a simple row looks like:
[
    'id' => 1,
    'band' => 'Led Zeppelin',
    'album' => 'Led Zeppelin II',
    'year' => object(Cake\I18n\Date) {
        'time' => '1969-01-01T00:00:00+00:00',
        'timezone' => 'UTC'
    }
]
```

You may want to manipulate some data and write it back to excel file. This is also possible.

```
$row = $table->newEntity([
    'band' => 'Genesis',
    'album' => 'Selling England by the Pound',
    'year' => '1973'
]);
$table->save($row);
```

Now the new record is saved, but excel file has not been updated yet. You have to call `writeSpreadsheet()` method:

```
$table->writeSpreadsheet();
```

You may also want to read or write only some of the rows and columns.

```
use Robotusers/Excel/Registry;

$table = $registry->get('path/to/records.xlsx', 'Albums', [
    'startRow' => 2,
    'endRow' => 3,
    'startColumn' => 'B',
    'endColumn' => 'B'
]);

$row = $table->find()->first()->toArray();

//this is how a simple row looks like:
[
    '_row' => 1,
    'B' => 'Machine Head'
]
```

Note that `_row` does not match the real row index. To keep original row indexes you must use `keepOriginalRows` option.

```
use Robotusers/Excel/Registry;

$table = $registry->get('path/to/records.xlsx', 'Albums', [
    'startRow' => 2,
    'endRow' => 3,
    'startColumn' => 'B',
    'endColumn' => 'B',
    'keepOriginalRows' => true
]);

$row = $table->find()->first()->toArray();

//this is how a simple row looks like:
[
    '_row' => 2,
    'B' => 'Machine Head'
]
```

The same principle applies to writing to a file. If you delete the second row it won't become empty in result excel file when `keepOriginalRows` is `false`. You have to set this option to `true` if you want to keep rows consistency across the table and the file.

Behavior
--------

[](#behavior)

This plugin provides a behavior which could be added to any table.

```
//AlbumsTable.php

public function initialize()
{
    $this->addBehavior('Robotusers/Excel.Excel', [
        'columnMap' => [
            'A' => 'band',
            'B' => 'album',
            'C' => 'year'
        ]
    ]);
}
```

If you want to load data into your table you have to set a worksheet instance.

```
use Cake\Filesystem\File;

$file = new File('path/to/file.xls');
$spreadsheet = $table->getManager()->getSpreadsheet($file); // \PhpOffice\PhpSpreadsheet\Spreadsheet instance
$worksheet = $spreadsheet->getActiveSheet(); // \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet instance

$table->setWorksheet($worksheet)->readSpreadsheet();
```

Now your table is populated with excel data.

If you want to write your data back to excel file you have to set a file.

```
$table->setFile($file)->writeSpreadsheet();
```

Working with different tables
-----------------------------

[](#working-with-different-tables)

It is also possible to load data into any table.

```
use Robotusers\Excel\Excel\Manager;

$table = TableRegistry::get('SomeTable');
$manager = new Manager();

$file = new File('file.xlsx');
$spreadsheet = $manager->getSpreadsheet($file);
$worksheet = $spreadsheet->getActiveSheet();

$manager->read($worksheet, $table, [
    'columnMap' => [
        'A' => 'band',
        'B' => 'album',
        'C' => 'year'
    ]
]);

//manipulate your data...

//here you have to tell where properties should be placed
$manager->write($table, $worksheet, [
    'propertyMap' => [
        'band' => 'A',
        'album' => 'B',
        'year' => 'C'
    ]
]);
//to actually save the file you have to call save()
$writer = $manager->save($spreadsheet, $file);
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~55 days

Recently: every ~91 days

Total

9

Last Release

2893d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.5

0.6.0PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/18fc483c7a2ff01469642c6dd0ec7171c09c2683b4db7d9c9a1a27d662c5d290?d=identicon)[chcnetconsulting](/maintainers/chcnetconsulting)

---

Top Contributors

[![robertpustulka](https://avatars.githubusercontent.com/u/7437773?v=4)](https://github.com/robertpustulka "robertpustulka (32 commits)")[![chcnetconsulting](https://avatars.githubusercontent.com/u/2822555?v=4)](https://github.com/chcnetconsulting "chcnetconsulting (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chcnetconsulting-cakephp-excel/health.svg)

```
[![Health](https://phpackages.com/badges/chcnetconsulting-cakephp-excel/health.svg)](https://phpackages.com/packages/chcnetconsulting-cakephp-excel)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M710](/packages/maatwebsite-excel)[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[cakephp/migrations

Database Migration plugin for CakePHP

13912.0M220](/packages/cakephp-migrations)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k17](/packages/civicrm-civicrm-core)[in2code/powermail

Powermail is a well-known, editor-friendly, powerful and easy to use mailform extension for TYPO3 with a lots of features

982.5M38](/packages/in2code-powermail)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
