PHPackages                             gevman/yii2-excel-import - 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. [Database &amp; ORM](/categories/database)
4. /
5. gevman/yii2-excel-import

ActivePackage[Database &amp; ORM](/categories/database)

gevman/yii2-excel-import
========================

Export excel sheets to ActiveRecord models

1.0.0(8y ago)711.2k↓45%3MITPHP

Since Mar 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/gevorgmansuryan/Yii2-excel-import)[ Packagist](https://packagist.org/packages/gevman/yii2-excel-import)[ RSS](/packages/gevman-yii2-excel-import/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Yii2 Excel Importer
===================

[](#yii2-excel-importer)

Import excel to ActiveRecord models

installation
------------

[](#installation)

using composer

```
composer require gevman/yii2-excel-import
```

methods
-------

[](#methods)

#### \_\_constructor

[](#__constructor)

supports array parameter with following attributes

- `filePath` - full path to excel file to be imported
- `activeRecord` - ActiveRecord class name where imported data should be saved
- `scenario` - ActiveRecord scenario, if leave empty no scenario will be set
- `skipFirstRow` - if true will skip excel's first row (eg. heading row), otherwise will try save first row also
- `fields[]` - array of field definitions

##### fields\[\]

[](#fields)

- `attribute` - attribute name from Your ActieRecord class
- `value` - if callable passed it will receive current row, and return value will be saved to AR, otherwise it will find element which key is passed value in current row

#### validate

[](#validate)

validates each populated AR model, and returns false if there's any error, otherwise it will return true

#### save

[](#save)

Saves populated AR models, and returns an array of each saved AR model's primary key if models is not validated yet, it will validate all models before save

#### getErrors

[](#geterrors)

Will return array of AR model errors indexed by row's index

#### getModels

[](#getmodels)

Will return array of populated AR models

examples
--------

[](#examples)

- Define Fields

```
$uploadedFile = \yii\web\UploadedFile::getInstanceByName('file');

$importer = new \Gevman\Yii2Excel\Importer([
    'filePath' => $uploadedFile->tempName,
    'activeRecord' => Product::class,
    'scenario' => Product::SCENARIO_IMPORT,
    'skipFirstRow' => true,
    'fields' => [
        [
            'attribute' => 'keywords',
            'value' => 1,
        ],
        [
            'attribute' => 'itemTitle',
            'value' => 2,
        ],
        [
            'attribute' => 'marketplaceTitle',
            'value' => 3,
        ],
        [
            'attribute' => 'brand',
            'value' => function ($row) {
                return strval($row[4]);
            },
        ],
        [
            'attribute' => 'category',
            'value' => function ($row) {
                return strval($row[4]);
            },
        ],
        [
            'attribute' => 'mpn',
            'value' => function ($row) {
                return strval($row[6]);
            },
        ],
        [
            'attribute' => 'ean',
            'value' => function ($row) {
                return strval($row[7]);
            },
        ],
        [
            'attribute' => 'targetPrice',
            'value' => 8,
        ],
        [
            'attribute' => 'photos',
            'value' => function ($row) {
                $photos = [];
                foreach (StringHelper::explode(strval($row[11]), ',', true, true) as $photo) {
                    if (filter_var($photo, FILTER_VALIDATE_URL)) {
                        $file = @file_get_contents($photo);
                        if ($file) {
                            $filename = md5($file) . '.jpg';
                            file_put_contents(Yii::getAlias("@webroot/gallery/$filename"), $file);
                            $photos[] = $filename;
                        }
                    } else {
                        $photos[] = $photo;
                    }
                }

                return implode(',', $photos);
            }
        ],
        [
            'attribute' => 'currency',
            'value' => 13,
        ],
    ],
]);
```

- Validate, Save, and show errors

```
if (!$importer->validate()) {
    foreach($importer->getErrors() as $rowNumber => $errors) {
        echo "$rowNumber errors " . implode('', $errors);
    }
} else {
    $importer->save();
}
```

of just

```
$importer->save();

foreach($importer->getErrors() as $rowNumber => $errors) {
    echo "$rowNumber errors " . implode('', $errors);
}
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

2985d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11891855?v=4)[Gevorg Mansuryan](/maintainers/gevorgmansuryan)[@gevorgmansuryan](https://github.com/gevorgmansuryan)

---

Top Contributors

[![gevorgmansuryan](https://avatars.githubusercontent.com/u/11891855?v=4)](https://github.com/gevorgmansuryan "gevorgmansuryan (7 commits)")

---

Tags

composerphp7yiiyii2yii2-extensionyiiframework

### Embed Badge

![Health badge](/badges/gevman-yii2-excel-import/health.svg)

```
[![Health](https://phpackages.com/badges/gevman-yii2-excel-import/health.svg)](https://phpackages.com/packages/gevman-yii2-excel-import)
```

###  Alternatives

[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[yii2tech/illuminate

Yii2 to Laravel Migration Package

11315.1k](/packages/yii2tech-illuminate)[mootensai/yii2-relation-trait

Yii 2 Models load with relation, &amp; transaction save with relation

47220.3k9](/packages/mootensai-yii2-relation-trait)[nhkey/yii2-activerecord-history

Storage history of changes to ActiveRecord

46143.4k1](/packages/nhkey-yii2-activerecord-history)[dmstr/yii2-db

Database extensions

19618.8k6](/packages/dmstr-yii2-db)[spanjeta/yii2-backup

Database Backup and Restore functionality

285.0k1](/packages/spanjeta-yii2-backup)

PHPackages © 2026

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