PHPackages                             popov/php-importer - 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. [PDF &amp; Document Generation](/categories/documents)
4. /
5. popov/php-importer

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

popov/php-importer
==================

Universal fast importer tables for different formats, such as Excel or CSV

0.1.2(9y ago)5200MITPHPPHP &gt;=5.5

Since Jun 27Pushed 6y ago3 watchersCompare

[ Source](https://github.com/popovserhii/php-importer)[ Packagist](https://packagist.org/packages/popov/php-importer)[ RSS](/packages/popov-php-importer/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

PHP Importer
============

[](#php-importer)

Universal importer for different table formats like excel or csv

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

[](#installation)

Install it with `composer`

```
composer require popov/php-importer -o
```

Supported drivers
-----------------

[](#supported-drivers)

1. LibXl ([commercial](http://www.libxl.com/))
2. Excel
3. Soap
4. Csv (not implemented yet)

Requirements
------------

[](#requirements)

**Importer** use [`INSERT ... ON DUPLICATE KEY UPDATE Syntax`](http://www.mysqltutorial.org/mysql-insert-or-update-on-duplicate-key-update) in background for reduce number of queries to database.

You should have only one unique field in your table otherwise you can get undesirable result. If you need to have [several unique fields](https://stackoverflow.com/a/35168085/1335142) you should group them with [`UNIQUE Constraint`](http://www.mysqltutorial.org/mysql-unique-constraint/)such as `UNIQUE (field_1, field_2, ...)`

Usage
-----

[](#usage)

### Example import File

[](#example-import-file)

NominalSerial3%30023453%30023463%30023465%50023445%5002345### Standalone

[](#standalone)

```
use Popov\Importer\Factory\DriverCreator;
use Popov\Importer\Importer;
use Popov\Db\Db;

$config = [
    'tasks' => [
        'discount-card' => [
            'driver' => 'libxl',
            'fields' => [
                [
                    // mapping fields in file to db fields with apply filters
                    'Nominal' => ['name' => 'discount', '__filter' => ['percentToInt']],
                    'Serial' => 'serial',

                    // table where save imported data
                    '__table' => 'discount_card',
                    // shortcut name
                    '__codename' => 'discount',
                    // unique field name for avoid duplicate
                    '__identifier' => 'serial'
                ],
            ],
        ],
    ],
];

$pdo = new PDO('mysql:host=myhost;dbname=mydb', 'login', 'password');
$db = (new Db())->setPdo($pdo);

$factory = new DriverCreator($config);
$importer = new Importer($factory, $db);

if ($importer->import('discount-card', '/path/to/file.xls')) {
  echo 'Success import!';
} else {
  var_dump($importer->getErrors());
}
```

### Advanced Usage

[](#advanced-usage)

Most popular PHP frameworks implement IoC pattern and they also implement standard interface `Interop\Container\ContainerInterface`. This library support this functionality. You can pass your own IoC to *Factory* and be happy with creating objects.

```
$pdo = new PDO('mysql:host=myhost;dbname=mydb', 'login', 'password');
$db = (new Db())->setPdo($pdo);

$container = /* getYourContainer */;
$factory = new DriverCreator($config, $container);
$importer = new Importer($factory, $db);

```

Configuration
-------------

[](#configuration)

Options marked with `*` are required.

### `driver` \*

[](#driver-)

Driver is handler for data from `source`. You can use one of the registered drivers or create your own.

```
['driver' => 'Excel']
```

#### `driver_options`

[](#driver_options)

You can pass any custom options to driver, there is no limit for it.

##### Excel options

[](#excel-options)

```
[
    'driver' => 'Excel',
    "driver_options" => [
        "path" => "data/path/to/excel.xlsx",
        "sheet" => [
            "name" => "Sheet Name",
            "skip" => 2,
        ],
    ],
]

```

##### `path`

[](#path)

Path to file which should be handled.

##### `sheet: name`

[](#sheet-name)

Name of the sheet which should be handled. By default first sheet is taken.

##### `sheet: skip`

[](#sheet-skip)

Skip first *N* rows in file. By default first row is taken.

---

\###`fields`Mapping fields from one resource to new (MySQL, CSV, Excel)

The simples mapping can be written as:

```
// from   =>   to
['Serial' => 'serial']
```

Fields filtration and preparation can be grouped in chain

```
[
    'Nominal' => ['name' => 'discount', '__filter' => ['trim', 'percentToInt']]
]
```

*\_\_filter* - reserved name for filtration

*\_\_prepare* - reserved name for preparation

All reserved options begin with "\_\_" (double underscore).

#### `__table`

[](#__table)

```
'__table' => 'table_name',
```

*Required*. A table where to save imported data.

#### `__codename`

[](#__codename)

```
'__codename' => 'discount',
```

*Required*. Shortcut unique name for config related to table.

#### `__identifier`

[](#__identifier)

```
'__identifier' => 'serial',
// or
'__identifier' => ['asin', 'marketplace'],
```

Unique field name for avoid duplicated items. Identifier can be as one field such as multiple fields.

#### `__ignore`

[](#__ignore)

```
'__ignore' => ['comment'],
```

Fields which should be ignored in save operation. These fields can be used in data filtration.

#### `__exclude`

[](#__exclude)

```
'__exclude' => false,
```

*Bool*. Exclude table from save operation. All fields can be used in data filtration.

#### `__exclude`

[](#__exclude-1)

```
'__foreign' => ['customer_table' => 'customerId'],
```

This option is actual if set up minimum two group of fields in config. For example, if you have customer and review info, you put customer info in first group of fields and review info in second group of fields. When first group will be saved the ID will be marked in memory and second group can use this value.

### Options

[](#options)

#### `mode`

[](#mode)

```
'__options' => [
    'mode' => 'save'
]
```

*save* - save new and excited data

*update* - only update excited data

Integration with ZF2
--------------------

[](#integration-with-zf2)

There's a [module](https://github.com/popovserhii/zfc-importer) for that!

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.7% 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 ~63 days

Total

2

Last Release

3545d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7dbdbd3abed25e11e97a69bc611daa3fe33ad5d1805f2fb32d491c888c4dfb51?d=identicon)[Serhii Popov](/maintainers/Serhii%20Popov)

---

Top Contributors

[![popovserhii](https://avatars.githubusercontent.com/u/1991183?v=4)](https://github.com/popovserhii "popovserhii (41 commits)")[![DayOut](https://avatars.githubusercontent.com/u/7451037?v=4)](https://github.com/DayOut "DayOut (6 commits)")[![stagemteam](https://avatars.githubusercontent.com/u/37902825?v=4)](https://github.com/stagemteam "stagemteam (1 commits)")[![vladgemtyp](https://avatars.githubusercontent.com/u/12100554?v=4)](https://github.com/vladgemtyp "vladgemtyp (1 commits)")

---

Tags

excelcsvimporteragere

### Embed Badge

![Health badge](/badges/popov-php-importer/health.svg)

```
[![Health](https://phpackages.com/badges/popov-php-importer/health.svg)](https://phpackages.com/packages/popov-php-importer)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M712](/packages/maatwebsite-excel)[rap2hpoutre/fast-excel

Fast Excel import/export for Laravel

2.3k24.9M47](/packages/rap2hpoutre-fast-excel)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.1k57.6M131](/packages/openspout-openspout)[gotenberg/gotenberg-php

A PHP client for interacting with Gotenberg, a developer-friendly API for converting numerous document formats into PDF files, and more!

3685.2M19](/packages/gotenberg-gotenberg-php)[nuovo/spreadsheet-reader

Spreadsheet reader library for Excel, OpenOffice and structured text files

669863.2k8](/packages/nuovo-spreadsheet-reader)[faisalman/simple-excel-php

Easily parse / convert / write between Microsoft Excel XML / CSV / TSV / HTML / JSON / etc formats

582599.4k1](/packages/faisalman-simple-excel-php)

PHPackages © 2026

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