PHPackages                             sateler/yii2-excelparser - 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. sateler/yii2-excelparser

ActiveLibrary

sateler/yii2-excelparser
========================

Parse excel files using PHP\_Excel into yii2 models

v1.0.2(3y ago)15841BSD-3-ClausePHP

Since Feb 27Pushed 3y ago3 watchersCompare

[ Source](https://github.com/sateler/yii2-excelparser)[ Packagist](https://packagist.org/packages/sateler/yii2-excelparser)[ RSS](/packages/sateler-yii2-excelparser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (14)Used By (0)

yii2-excelparser
================

[](#yii2-excelparser)

Parse excel files using PHP\_Excel into yii2 models

Examples:
=========

[](#examples)

Model

```
class ImportForm extends \yii\base\Model
{
    private static $fields = [
        'Name' => 'name',
        'Code' => 'code',
        'Subject' => 'subject',
    ];

    private static $required = [
        'Name',
        'Code',
    ];

    public $file;

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            ['file', 'setFileProp', 'skipOnEmpty' => false],
            [['file'], 'file', 'skipOnEmpty' => false],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'file' => 'Archivo',
        ];
    }

    public function setFileProp() {
        $this->file = UploadedFile::getInstance($this, 'file');
    }

    public function import() {
        try {
            $parser = new ExcelParser([
                'fileName' => $this->file->tempName,
                //'worksheetName' => 'Sheet 1',
                'fields' => self::$fields,
                'requiredFields' => self::$required,
                'setNullValues' => false,
                'modelClass' => SomeModel::className(),
                // Use either modelClass or createObject...
                // createObject is called before parsing the row.
                'createObject' => function ($prevRow) use ($someData) {
                    $newObj = new SomeModel();
                    $newObj->parent_id = $someData->id;
                    if (!$prevRow) {
                        return $newObj;
                    }
                    // set some defualt data from previous created object
                    foreach(self::$copyFields as $field) {
                        $newObj->$field = $prevRow->$field;
                    }
                    return $newObj;
                },
                // Will save the data in an internal array, set to false for large datasets to save memory
                'saveData' => false,
                // Modify parsed header columns, each item is a [name => column_number] pair
                'modifyHeaderColumns' => function($cols) {
                    $cols["Custom Header"] = 11; // get the values from column 11 for each row as the 'Custom Header' attribute
                    return $cols;
                },
                // Callback after object has been created and parsed
                'onObjectParsed' => function(SomeModel $data, $rowIndex) {
                    return $data->save();
                },
            ]);
        }
        if ($parser->getError()) {
            Yii::error("ExcelParser Error: " . $parser->getError());
            $this->addError('file', 'Archivo con formato inválido');
            return false;
        }

        // If 'savedata' is set to true, then get the data:
        $allData = $parser->getData();
        foreach($allData as $i => $data) {
            if (!$data->save()) {
                $this->addError('file', "Error en fila $i: " . implode("\n", $data->getFirstErrors()));
                return false;
            }
            unset($allData[$i]);
        }
        return true;
    }
}
```

Controller

```
    public function actionImport()
    {
        $form = new ImportForm;

        if ($form->load(Yii::$app->request->post()) && $form->validate()) {
            if($form->import()) {
                Yii::$app->session->setFlash('success', 'Success');
                return $this->redirect(['import']);
            }
            else {
                Yii::$app->session->setFlash('error', 'Error');
            }
        }

        return $this->render('import', [
            'model' => $form,
        ]);
    }
```

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 75% 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 ~172 days

Recently: every ~378 days

Total

12

Last Release

1457d ago

Major Versions

0.1.8 → v1.0.02021-05-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/0dccda8434771641535b87b5ba40f569fa695da1f03dd2ef81c02d851bc175c1?d=identicon)[fsateler](/maintainers/fsateler)

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

---

Top Contributors

[![rsateler](https://avatars.githubusercontent.com/u/1533946?v=4)](https://github.com/rsateler "rsateler (15 commits)")[![xotion](https://avatars.githubusercontent.com/u/7204891?v=4)](https://github.com/xotion "xotion (3 commits)")[![fsateler](https://avatars.githubusercontent.com/u/1322013?v=4)](https://github.com/fsateler "fsateler (1 commits)")[![gbordoni](https://avatars.githubusercontent.com/u/13774052?v=4)](https://github.com/gbordoni "gbordoni (1 commits)")

### Embed Badge

![Health badge](/badges/sateler-yii2-excelparser/health.svg)

```
[![Health](https://phpackages.com/badges/sateler-yii2-excelparser/health.svg)](https://phpackages.com/packages/sateler-yii2-excelparser)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)

PHPackages © 2026

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