PHPackages                             emizoripx/office-php74 - 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. emizoripx/office-php74

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

emizoripx/office-php74
======================

Document generation from existing Excel templates | Export tables to Excel (Grids)

2.1.0(3y ago)086MITPHP

Since Mar 30Pushed 3y agoCompare

[ Source](https://github.com/emizoripx/office)[ Packagist](https://packagist.org/packages/emizoripx/office-php74)[ Docs](https://github.com/AnourValar/office)[ RSS](/packages/emizoripx-office-php74/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (16)Used By (0)

> Clone of  for internal compatibility with PHP7.4

Office: Documents | Reports | Grids
===================================

[](#office-documents--reports--grids)

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

[](#installation)

### Minimal

[](#minimal)

```
composer require anourvalar/office
```

### To work with default driver - Phpspreadsheet is required:

[](#to-work-with-default-driver---phpspreadsheet-is-required)

```
composer require phpoffice/phpspreadsheet "^1.23"
```

### To save documents as PDF - Mpdf is required:

[](#to-save-documents-as-pdf---mpdf-is-required)

```
composer require mpdf/mpdf: "^8.0"
```

Generate a document from an XLSX (Excel) template
-------------------------------------------------

[](#generate-a-document-from-an-xlsx-excel-template)

### One-dimensional table

[](#one-dimensional-table)

**template1.xlsx:**

[![Demo](https://camo.githubusercontent.com/8727e7f29013319bcb3f98aaf5d051507128eeed1aeb80f6f72b07e22bfebaad/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d31302e706e67)](https://camo.githubusercontent.com/8727e7f29013319bcb3f98aaf5d051507128eeed1aeb80f6f72b07e22bfebaad/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d31302e706e67)

```
$data = [
    // scalar
    'vat' => 'No',
    'total' => [
        'price' => 2004.14,
        'qty' => 3,
    ],

    // one-dimensional table
    'products' => [
        [
            'name' => 'Product #1',
            'price' => 989,
            'qty' => 1,
            'date' => new \DateTime('2022-03-30'),
        ],
        [
            'name' => 'Product #2',
            'price' => 1015.14,
            'qty' => 2,
            'date' => new \DateTime('2022-03-31'),
        ],
    ],
];

// Save as XLSX (Excel)
(new \EmizorIpx\OfficePhp74\SheetsService())
    ->generate(
        'template1.xlsx', // path to template
        $data // input data
    )
    ->saveAs(
        'generated_document.xlsx', // path to save
        \EmizorIpx\OfficePhp74\Format::Xlsx // save format
    );

// Available formats:
// \EmizorIpx\OfficePhp74\Format::Xlsx
// \EmizorIpx\OfficePhp74\Format::Pdf
// \EmizorIpx\OfficePhp74\Format::Html
// \EmizorIpx\OfficePhp74\Format::Ods
```

**generated\_document.xlsx:**

[![Demo](https://camo.githubusercontent.com/63ba78d71f5b64c7619217d750e023e6971ea8caf732fab1e0d58bb83b50438b/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d31312e706e67)](https://camo.githubusercontent.com/63ba78d71f5b64c7619217d750e023e6971ea8caf732fab1e0d58bb83b50438b/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d31312e706e67)

**The same template with empty data**

[![Demo](https://camo.githubusercontent.com/dc9aa94e5b2337f132b3a5ed468339838086db7270c38cd04b21cd6b42298e6b/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d31322e706e67)](https://camo.githubusercontent.com/dc9aa94e5b2337f132b3a5ed468339838086db7270c38cd04b21cd6b42298e6b/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d31322e706e67)

### Two-dimensional table

[](#two-dimensional-table)

**template2.xlsx:**

[![Demo](https://camo.githubusercontent.com/1f8e50ed0fb7dc8b554a076f8807d6c95fdce4586abcb469a6e651153acf56c5/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d32302e706e67)](https://camo.githubusercontent.com/1f8e50ed0fb7dc8b554a076f8807d6c95fdce4586abcb469a6e651153acf56c5/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d32302e706e67)

```
$data = [
    'best_manager' => 'Sveta',

    // two-dimensional table
    'managers' => [
        'titles' => [[ 'William', 'James', 'Sveta' ]],

        'values' => [
            [ // additional row
                'month' => 'January',
                'amount' => [700, 800, 900], // additional columns
            ],
            [
                'month' => 'February',
                'amount' => [7000, 8000, 9000],
            ],
            [
                'month' => 'March',
                'amount' => [70000, 80000, 90000],
            ],
        ],
    ],
];

// Save as XLSX (Excel)
(new \EmizorIpx\OfficePhp74\SheetsService())
    ->generate('template2.xlsx', $data)
    ->saveAs('generated_document.xlsx'); // second argument (format) is optional
```

**generated\_document.xlsx:**

[![Demo](https://camo.githubusercontent.com/c7b935910c2dad2f41257d9ee6b27ca87470edd0c484b72b79607b0f0498071b/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d32312e706e67)](https://camo.githubusercontent.com/c7b935910c2dad2f41257d9ee6b27ca87470edd0c484b72b79607b0f0498071b/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d32312e706e67)

### Additional Features

[](#additional-features)

**template3.xlsx:**

[![Demo](https://camo.githubusercontent.com/ec25d52c1ebbaee67e258132f6719030527034b87d6ff74e8676f3021b800281/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d33302e706e67)](https://camo.githubusercontent.com/ec25d52c1ebbaee67e258132f6719030527034b87d6ff74e8676f3021b800281/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d33302e706e67)

```
$data = [
    'foo' => 'Hello',

    'bar' => function (\EmizorIpx\OfficePhp74\Drivers\SheetsInterface $driver, $cell) {
        $driver->insertImage('logo.png', $cell, ['width' => 100, 'offset_y' => -45]);
        return 'Logo!'; // replace marker "[bar]" with return value
    }
];

(new \EmizorIpx\OfficePhp74\SheetsService())
    ->hookValue(function (SheetsInterface $driver, $cell, $value, int $sheetIndex) {
        // Hook will be called for every cell which is changing

        $value .= ' world';
        return $value;
    })
    ->generate(
        'template3.ods', // ods template
        $data,
        true // cells auto format instead of template setup
    )
    ->saveAs('generated_document.xlsx');

// Available hooks:
// hookLoad: Closure(SheetsInterface $driver, string $templateFile, Format $templateFormat)
// hookBefore: Closure(SheetsInterface $driver, array &$data)
// hookValue: Closure(SheetsInterface $driver, string $cell, mixed $value, int $sheetIndex)
// hookAfter: Closure(SheetsInterface $driver)
```

**generated\_document.xlsx:**

[![Demo](https://camo.githubusercontent.com/f404cb25de06b5e45e918539cddd3d1f90f6a6f5acd7ec10c36a13f8acd286a3/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d33312e706e67)](https://camo.githubusercontent.com/f404cb25de06b5e45e918539cddd3d1f90f6a6f5acd7ec10c36a13f8acd286a3/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d33312e706e67)

### Dynamic templates

[](#dynamic-templates)

```
$data = [
    'group1' => [
        'name' => 'Group 1',
        'products' => [
            ['name' => 'Product 1', 'stock' => 101],
            ['name' => 'Product 2', 'stock' => 102],
        ],
    ],
    'group2' => [
        'name' => 'Group 2',
        'products' => [
            ['name' => 'Product 3', 'stock' => 103],
            ['name' => 'Product 4', 'stock' => 104],
        ],
    ],
];

(new \EmizorIpx\OfficePhp74\SheetsService())
    ->hookLoad(function ($driver, string $templateFile, $templateFormat)
    {
        // create empty document instead of using existing
        return $driver->create();
    })
    ->hookBefore(function ($driver, array &$data)
    {
        // place markers on-fly
        $row = 1;
        foreach (array_keys($data) as $group) {
            // group's title
            $driver
                ->setValue("A$row", "[{$group}.name]")
                ->mergeCells("A$row:B$row")
                ->setStyle("A$row", ['align' => 'center', 'bold' => true]);
            $row++;

            // group's products
            $driver
                ->setValue("A$row", "[$group.products.name]")
                ->setValue("B$row", "[$group.products.stock]");
            $row++;
        }
    })
    ->generate('', $data)
    ->saveAs('generated_document.xlsx');
```

**Dynamic template overview**

[![Demo](https://camo.githubusercontent.com/62caeb2ddc65885e6ed2b28f4128672ef18e28a745bbc9d11b9d44febb04723b/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d36312e706e67)](https://camo.githubusercontent.com/62caeb2ddc65885e6ed2b28f4128672ef18e28a745bbc9d11b9d44febb04723b/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d36312e706e67)

**generated\_document.xlsx:**

[![Demo](https://camo.githubusercontent.com/c3f9abd23579de8df70f9896cdc1bb8d6bf34941b491dc461945a1b06e19695c/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d36322e706e67)](https://camo.githubusercontent.com/c3f9abd23579de8df70f9896cdc1bb8d6bf34941b491dc461945a1b06e19695c/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d36322e706e67)

### Merge (union) few documents to a single file

[](#merge-union-few-documents-to-a-single-file)

```
$dataA = ['foo' => 'hello'];
$dataB = ['foo' => 'world'];

$documentA = (new \EmizorIpx\OfficePhp74\SheetsService())->generate('template.xlsx', $dataA);
$documentB = (new \EmizorIpx\OfficePhp74\SheetsService())->generate('template.xlsx', $dataB);

$mixer = new \EmizorIpx\OfficePhp74\Mixer();
$mixer($documentA, $documentB)->saveAs('generated_document.xlsx');
```

Export table (Grid)
-------------------

[](#export-table-grid)

### Simple usage

[](#simple-usage)

```
$data = [
    ['William', 3000],
    ['James', 4000],
    ['Sveta', 5000],
];

// Save as XLSX (Excel)
(new \EmizorIpx\OfficePhp74\GridService())
    ->generate(
        ['Name', 'Sales'], // headers
        $data // data
    )
    ->saveAs('generated_grid.xlsx');
```

**generated\_grid.xlsx:**

[![Demo](https://camo.githubusercontent.com/0bb415562d487544a410f148a635b9bc6cf58a50cc425391cfad2616ae542a80/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d34312e706e67)](https://camo.githubusercontent.com/0bb415562d487544a410f148a635b9bc6cf58a50cc425391cfad2616ae542a80/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d34312e706e67)

### Advanced usage

[](#advanced-usage)

```
$headers = [
    ['title' => 'Name', 'width' => 30],
    ['title' => 'Sales'],
];

$data = function () {
    yield ['name' => 'William', 'sales' => 3000];
    yield ['name' => 'James', 'sales' => 4000];
    yield ['name' => 'Sveta', 'sales' => 5000];
};

// Save as XLSX (Excel)
(new \EmizorIpx\OfficePhp74\GridService())
    ->hookHeader(function (GridInterface $driver, mixed $header, $key, $column)
    {
        if (isset($header['width'])) {
            $driver->setWidth($column, $header['width']); // column with fixed width
        } else {
            $driver->autoWidth($column); // column with auto width
        }

        return $header['title'];
    })
    ->hookRow(function (GridInterface $driver, mixed $row, $key)
    {
        return [
            $row['name'],
            $row['sales'],
        ];
    })
    ->hookAfter(function (
        GridInterface $driver,
        string $headersRange,
        string $dataRange,
        string $totalRange,
        array $columns
    ) {
        $driver->setSheetTitle('Foo');

        $driver->setStyle(
            $headersRange, // A1:B1
            ['bold' => true, 'background_color' => 'EEEEEE']
        );

        $driver->setStyle(
            $totalRange, // A1:B4
            ['borders' => true, 'align' => 'left']
        );
    })
    ->generate($headers, $data)
    ->saveAs('generated_grid.xlsx');
```

**generated\_grid.xlsx:**

[![Demo](https://camo.githubusercontent.com/26373606dad91c05480bdaae19a0a23552662bb6ca27d0c29ec1b88c9e5542ee/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d35312e706e67)](https://camo.githubusercontent.com/26373606dad91c05480bdaae19a0a23552662bb6ca27d0c29ec1b88c9e5542ee/68747470733a2f2f616e6f75722e72752f7265736f75726365732f6f66666963652d76312d35312e706e67)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.3% 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 ~8 days

Recently: every ~22 days

Total

15

Last Release

1390d ago

Major Versions

1.5.5 → 2.0.02022-05-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ec0aca4b543b0eb7586d3dea32e3e848017cf75d5a85c59a38d9eddb56a75aa?d=identicon)[alvaro-ipx](/maintainers/alvaro-ipx)

---

Top Contributors

[![AnourValar](https://avatars.githubusercontent.com/u/54237693?v=4)](https://github.com/AnourValar "AnourValar (14 commits)")[![alvaro-ez](https://avatars.githubusercontent.com/u/76056894?v=4)](https://github.com/alvaro-ez "alvaro-ez (1 commits)")

---

Tags

pdfexportgeneratorexcelxlsxlsxanourvalartemplateodsgridreportviewvariablesdocumentgenerateenginecontractfillmarkerstemplatertemplatorreplacers

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/emizoripx-office-php74/health.svg)

```
[![Health](https://phpackages.com/badges/emizoripx-office-php74/health.svg)](https://phpackages.com/packages/emizoripx-office-php74)
```

###  Alternatives

[anourvalar/office

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

24085.2k](/packages/anourvalar-office)[alhimik1986/php-excel-templator

PHP Spreadsheet extension for generating excel files from template

350336.7k1](/packages/alhimik1986-php-excel-templator)[icircle/docx-template-in-php

Create Templates in MS Word docx format and use them Creating Business documents using PHP

4422.7k](/packages/icircle-docx-template-in-php)[tomatophp/filament-docs

Manage your documents and contracts all in one place with template builder

422.6k](/packages/tomatophp-filament-docs)

PHPackages © 2026

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