PHPackages                             myclabs/xport - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. myclabs/xport

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

myclabs/xport
=============

Import/Export library for PHP

0.2.2(12y ago)204041MITPHPPHP &gt;=5.4.0

Since Jun 10Pushed 12y ago3 watchersCompare

[ Source](https://github.com/myclabs/Xport)[ Packagist](https://packagist.org/packages/myclabs/xport)[ Docs](https://github.com/myclabs/Xport)[ RSS](/packages/myclabs-xport/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (4)Dependencies (6)Versions (6)Used By (0)

Xport
=====

[](#xport)

[![Build Status](https://camo.githubusercontent.com/8f83a3d47a86a86a01666f4c5cba3b2038b4b6092a08bb27cf5599d209adca37/68747470733a2f2f7472617669732d63692e6f72672f6d79636c6162732f58706f72742e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/myclabs/Xport) [![Coverage Status](https://camo.githubusercontent.com/a1512e711990cf9055c02f4404e48fc5fc0c6a7b1c162f171e6db2a630f7cf20/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6d79636c6162732f58706f72742f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/myclabs/Xport?branch=master) [![Scrutinizer Quality Score](https://camo.githubusercontent.com/eccfe5beb62426391490b419cdbd6d6d1310410d73061affe386b3b2965a0536/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d79636c6162732f58706f72742f6261646765732f7175616c6974792d73636f72652e706e673f733d31666466616364363531336139633064616233303061343137633136343264383835623431323734)](https://scrutinizer-ci.com/g/myclabs/Xport/)

Xport is an import/export library for PHP.

It is targeted to support the following formats:

- Excel (xlsx and xls)
- OpenOffice (ods - to be implemented)
- PDF (to be implemented)
- XML (to be implemented)

It provides an object model for different formats (spreadsheet, document, XML…) and a language based on YAML and Twig to map your data (arrays, objects, …) onto the model.

Spreadsheet
-----------

[](#spreadsheet)

### Simple example

[](#simple-example)

Simple mapping file (YAML file):

```
sheets:
    # An empty sheet named "Home"
  - label: "Home"

    # Another sheet named "Contacts"
  - label: "Contacts"

    content:
    # Containing one table with 2 columns
      - type: VerticalTable
        columns:
          - "Name"
          - "Phone Number"
        lines:
          - foreach: "contacts as contact"
            do :
              - cells:
                - "{{ contact.name }}"
                - "{{ contact.phoneNumber }}"
```

Usage:

```
$modelBuilder = new SpreadsheetModelBuilder();
$export = new PHPExcelExporter();

$modelBuilder->bind('contacts', $contacts);

$export->export($modelBuilder->build('mapping.yml'), 'myFile.xslx');
```

The table will be filled with each item in the array `$contacts`.

The `path` configuration is a [PropertyAccess](http://symfony.com/doc/master/components/property_access/index.html) path, e.g. the `contact.phoneNumber` path can resolve to `$contact->getPhoneNumber()` or `$contact->phoneNumber`.

### Dynamic example

[](#dynamic-example)

You can use the `foreach` expression to generate dynamic content.

You can also use [Twig](http://twig.sensiolabs.org/) templating language.

Here is an example:

```
# Create one sheet per company
sheets:
  - foreach: companies as i => company
    do:
      - label: "{{ i + 1 }} - {{ company.name }}" # Twig expression, will result in (for example): "1 - My Company"
```

```
$modelBuilder = new SpreadsheetModelBuilder();
$export = new PHPExcelExporter();

$modelBuilder->bind('companies', $companies);

$export->export($modelBuilder->build(new YamlMappingReader('mapping.yml')), 'myFile.xslx');
```

Here is a more complete example:

```
sheets:

    # Create one sheet per company
  - foreach: companies as company
    do:

      - label: "{{ company.name }}"
        content:
            # One content(VerticalTable) per product, each, followed by an empty line

          - foreach: company.products as product
            do:

              - type: VerticalTable
                label: product.label
                columns:
                  - "Product"
                  - "Price"
                  - "Salesman"
                # One line per sale, each, preceded by an empty line
                lines:
                  - foreach: product.getSalesList() as sale
                    do:
                      -
                      - cells:
                          - "{{ product.name }}"
                          - "{{ sale.price }}"
                          - "{{ sale.salesman.name }}"

              - type: EmptyLine
```

### Functions

[](#functions)

Functions can be used in Twig expressions, and are defined as such:

```
$modelBuilder = new SpreadsheetModelBuilder();
$export = new PHPExcelExporter();

$modelBuilder->bindFunction('up', function($str) {
    return strtoupper($str);
});

$export->export($modelBuilder->build(new YamlMappingReader('mapping.yml')), 'myFile.xslx');
```

### File format

[](#file-format)

You can choose which file format to use through PHPExcel writers:

```
// ...
$export->export($spreadsheet, 'myFile.xslx', new PHPExcel_Writer_Excel2007());
```

Writers available:

- Excel 2007 (.xlsx): `PHPExcel_Writer_Excel2007`
- Excel classic (.xls): `PHPExcel_Writer_Excel5`
- CSV (.csv): `PHPExcel_Writer_CSV`

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 55% 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 ~82 days

Total

4

Last Release

4520d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/329a6111724074f5388e95dd41a03ccf3c43f4bfe1ecf27c94c9efc6f7823228?d=identicon)[mnapoli](/maintainers/mnapoli)

![](https://www.gravatar.com/avatar/8220feb8a3d9f1df987987c33494da696aca6929179a6281cdbe45623fcbec0f?d=identicon)[myclabs](/maintainers/myclabs)

---

Top Contributors

[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (61 commits)")[![valentin-claras](https://avatars.githubusercontent.com/u/4446791?v=4)](https://github.com/valentin-claras "valentin-claras (50 commits)")

---

Tags

pdfxmlexportexcelimport

### Embed Badge

![Health badge](/badges/myclabs-xport/health.svg)

```
[![Health](https://phpackages.com/badges/myclabs-xport/health.svg)](https://phpackages.com/packages/myclabs-xport)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.5M378](/packages/easycorp-easyadmin-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M524](/packages/shopware-core)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9417.2k55](/packages/open-dxp-opendxp)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1615.6k12](/packages/2lenet-crudit-bundle)

PHPackages © 2026

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