PHPackages                             tangwei666/php-excel-templator - 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. [Templating &amp; Views](/categories/templating)
4. /
5. tangwei666/php-excel-templator

ActiveLibrary[Templating &amp; Views](/categories/templating)

tangwei666/php-excel-templator
==============================

PHP Spreadsheet extension for generating excel files from template

v1.0.11(5y ago)01101MITPHPPHP &gt;=7.2

Since Oct 4Pushed 5y agoCompare

[ Source](https://github.com/tangwei666/php-excel-templator)[ Packagist](https://packagist.org/packages/tangwei666/php-excel-templator)[ RSS](/packages/tangwei666-php-excel-templator/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (13)Used By (0)

PHP Excel Templator
===================

[](#php-excel-templator)

[![Latest Stable Version](https://camo.githubusercontent.com/6035d02dc7682f37306e6d86567ae63d5e68a2bf6316456f26aa6aba381ad283/68747470733a2f2f706f7365722e707567782e6f72672f74616e677765693636362f7068702d657863656c2d74656d706c61746f722f762f737461626c65)](https://packagist.org/packages/tangwei666/php-excel-templator)[![Latest Unstable Version](https://camo.githubusercontent.com/587aa9543173e8dcfb7e3e5ae5763f932448b241a5f0611109bf693458e1dd6d/68747470733a2f2f706f7365722e707567782e6f72672f74616e677765693636362f7068702d657863656c2d74656d706c61746f722f762f756e737461626c65)](https://packagist.org/packages/tangwei666/php-excel-templator)[![License](https://camo.githubusercontent.com/b673ab79ac23d215706e5838eb4d42e42d8e487eddbb839e475ce0d58fc9ed3c/68747470733a2f2f706f7365722e707567782e6f72672f74616e677765693636362f7068702d657863656c2d74656d706c61746f722f6c6963656e7365)](https://packagist.org/packages/tangwei666/php-excel-templator)[![Total Downloads](https://camo.githubusercontent.com/20b94290fc41ae9ccc47c1e99a7fa220175416b6f363ec279c6c225dd6079d4c/68747470733a2f2f706f7365722e707567782e6f72672f74616e677765693636362f7068702d657863656c2d74656d706c61746f722f646f776e6c6f616473)](https://packagist.org/packages/tangwei666/php-excel-templator)[![Monthly Downloads](https://camo.githubusercontent.com/a6aa5f82204703668c7cf3c4a7345e00b0ede4155198ac0495fc44b57e301382/68747470733a2f2f706f7365722e707567782e6f72672f74616e677765693636362f7068702d657863656c2d74656d706c61746f722f642f6d6f6e74686c79)](https://packagist.org/packages/tangwei666/php-excel-templator)[![Daily Downloads](https://camo.githubusercontent.com/728eab55069e1509468584819878dde85fe31caa1fe870db05ada813ae175296/68747470733a2f2f706f7365722e707567782e6f72672f74616e677765693636362f7068702d657863656c2d74656d706c61746f722f642f6461696c79)](https://packagist.org/packages/tangwei666/php-excel-templator)

[Инструкция на русском языке (Russian)](README_ru.md)

It's PHP Spreadsheet extension that allows you to export excel files from an excel template. Using the extension you don’t need to create excel files from scratch using code, set styles and so on.

Demo screenshot:

[![Demo](readme_resources/demo.png)](readme_resources/demo.png)

Simple example
--------------

[](#simple-example)

There is a simplest example of how this might look (using less code). Suppose we have an excel file with the following template variables:

[![Template](readme_resources/template.png)](readme_resources/template.png)

The code will be as follows:

```
use tangwei666\PhpExcelTemplator\PhpExcelTemplator;
require_once('vendor/autoload.php'); // if you don't use framework

PhpExcelTemplator::saveToFile('./template.xlsx', './exported_file.xlsx', [
	'{current_date}' => date('d-m-Y'),
	'{department}' => 'Sales department',
]);

```

As a result, we get:

[![Exported file](readme_resources/exported_file.png)](readme_resources/exported_file.png)

Using this extension, we just create a template file with the styles we need and specify template variables in it. In the code, we just pass the parameters to template variables.

Features
--------

[](#features)

- We can insert several template variables in one table cell (if the data type is "string")
- We can insert a one-dimensional array, in this case additional rows will be created in the table
- We can insert a two-dimensional array, in this case the respective columns and rows are created in the table
- By specifying the value in the cells, you can change the styles of these cells, even when inserting arrays
- We can apply the same template on several sheets of the table

Features demo and usage examples are given in the folder "samples".

Restrictions:
-------------

[](#restrictions)

- Possible so-called side effects when using one-dimensional or two-dimensional arrays in one sheet. Especially when it is located asymmetrically. An example of side effects is also given in the folder "samples".

INSTALLATION:
-------------

[](#installation)

```
$ composer require tangwei666/php-excel-templator

```

### Template variable naming rules

[](#template-variable-naming-rules)

The rules can be any, but I can offer my recommendation for naming template variables:

- {var\_name} - for string values
- \[var\_name\] - for one-dimensional arrays
- \[\[var\_name\]\] - for two-dimensional arrays

### How to insert a one-dimensional array, so that the table create columns, not rows?

[](#how-to-insert-a-one-dimensional-array-so-that-the-table-create-columns-not-rows)

To do this, instead of a one-dimensional array, insert a two-dimensional one as follows:

```
$param['[[var_name]]'] = [['text 1', 'text 2', 'text 3']];

```

Using setters
-------------

[](#using-setters)

In the example above, the minimum code without setters was used. The data types (for example: a string, a one-dimensional array, or a two-dimensional array) in this code is automatically recognized and the necessary setter is chose. But if we want to use a specific setter, the same code will look like this:

```
use tangwei666\PhpExcelTemplator\PhpExcelTemplator;
use tangwei666\PhpExcelTemplator\params\ExcelParam;
use tangwei666\PhpExcelTemplator\params\CallbackParam;
use tangwei666\PhpExcelTemplator\setters\CellSetterStringValue;

require_once('vendor/autoload.php'); // if you don't use framework

$params = [
	'{current_date}' => new ExcelParam(CellSetterStringValue::class, date('d-m-Y')),
	'{department}' => new ExcelParam(CellSetterStringValue::class, 'Sales department'),
];
PhpExcelTemplator::saveToFile('./template.xlsx', './exported_file.xlsx', $params);

```

At the moment the extension has 3 kinds of setters:

- CellSetterStringValue (for string values)
- CellSetterArrayValue (for one-dimensional arrays)
- CellSetterArray2DValue (for two-dimensional arrays)

You ask, what for specify setters explicitly?

- First, because it's flexible: let's say you want to create your own setter with your own algorithms that eliminate the side effects, which I mentioned above.
- Secondly, in each setter, you can pass a callback function in which we can change the styles of the inserted cells. For example, you need to highlight with bold font the employees who made the best sales in this month.

Examples of code that uses all kinds of setters are listed in the folder "samples".

How to set styles without setters?
----------------------------------

[](#how-to-set-styles-without-setters)

In most cases to use the setters explicitly is not so convenient. I suppose you want to use minimum code. Therefore, I made it possible to set styles without using setters:

```
use tangwei666\PhpExcelTemplator\PhpExcelTemplator;
use tangwei666\PhpExcelTemplator\params\CallbackParam;
require_once('vendor/autoload.php'); // if you don't use framework

$params = [
	'{current_date}' => date('d-m-Y'),
	'{department}' => 'Sales department',
	'[sales_amount]' => [
		'10230',
		'45100',
		'70500',
	],
];

$callbacks = [
	'[sales_amount]' => function(CallbackParam $param) {
		$amount = $param->param[$param->row_index];
		if ($amount > 50000) {
			$cell_coordinate = $param->coordinate;
			$param->sheet->getStyle($cell_coordinate)->getFont()->setBold(true);
		}
	},
];

PhpExcelTemplator::saveToFile('./template.xlsx', './exported_file.xlsx', $params, $callbacks);

```

Special setter for special templates (CellSetterArrayValueSpecial)
------------------------------------------------------------------

[](#special-setter-for-special-templates-cellsetterarrayvaluespecial)

There are special templates, which require to insert the whole row, and not insert cell with shifting down. Moreover, it's required to merge cells, as well as the cell in which there was a template variable.

[![Special template](readme_resources/special_template.png)](readme_resources/special_template.png)

For these templates, a special setter has been created: CellSetterArrayValueSpecial. Examples of code that uses it is given in folder: samples/8\_special\_template.

Events
------

[](#events)

The following are possible events and an explanation of why they can be applied:

```
$events = [
    PhpExcelTemplator::BEFORE_INSERT_PARAMS => function(Worksheet $sheet, array $templateVarsArr) {
        // fires before inserting values into template variables
    },
    PhpExcelTemplator::AFTER_INSERT_PARAMS => function(Worksheet $sheet, array $templateVarsArr) {
        // fires after inserting values into template variables.
        // It is used if you want to insert values​into a spreadsheet after columns and rows have been created.
        // For example, when inserting an array of images.
        // If you insert images using $callbacks, then the images can shift to the right due to the fact that on the next line the template variable can create additional columns.
        // See an example: samples/10_images
    },
    PhpExcelTemplator::BEFORE_SAVE => function(Spreadsheet $spreadsheet, IWriter $writer) {
        // fires before saving to a file. It is used when you need to modify the $writer or $spreadsheet object before saving, for example, $writer->setPreCalculateFormulas(false);
    },
];
$callbacks = [];
$templateFile = './template.xlsx';
$fileName = './exported_file.xlsx';
$params = [
	// ...
];

PhpExcelTemplator::saveToFile($templateFile, $fileName, $params, $callbacks, $events);
```

###  Health Score

29

—

LowBetter than 63% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 88.2% 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 ~56 days

Recently: every ~151 days

Total

12

Last Release

2108d ago

PHP version history (3 changes)v1.0PHP &gt;=5.4.0

v1.0.10PHP &gt;=5.6.0

v1.0.11PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/bc1729c91c7ea40cb04a658ddced4e49cfb3caed90a5c994b722840f46c25eb7?d=identicon)[tangwei666](/maintainers/tangwei666)

---

Top Contributors

[![alhimik1986](https://avatars.githubusercontent.com/u/7689682?v=4)](https://github.com/alhimik1986 "alhimik1986 (15 commits)")[![tangwei666](https://avatars.githubusercontent.com/u/29201660?v=4)](https://github.com/tangwei666 "tangwei666 (2 commits)")

---

Tags

phpexceltemplatetemplatertemplator

### Embed Badge

![Health badge](/badges/tangwei666-php-excel-templator/health.svg)

```
[![Health](https://phpackages.com/badges/tangwei666-php-excel-templator/health.svg)](https://phpackages.com/packages/tangwei666-php-excel-templator)
```

###  Alternatives

[alhimik1986/php-excel-templator

PHP Spreadsheet extension for generating excel files from template

354329.4k1](/packages/alhimik1986-php-excel-templator)[anourvalar/office

Generate documents from existing Excel &amp; Word templates | Export tables to Excel (Grids)

23881.6k](/packages/anourvalar-office)

PHPackages © 2026

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