PHPackages                             ciniran/yii2-excel - 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. ciniran/yii2-excel

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

ciniran/yii2-excel
==================

excel tools

1.0.0(7y ago)84421[1 issues](https://github.com/ciniran/yii2-excel/issues)MITPHP

Since Sep 15Pushed 7y ago1 watchersCompare

[ Source](https://github.com/ciniran/yii2-excel)[ Packagist](https://packagist.org/packages/ciniran/yii2-excel)[ RSS](/packages/ciniran-yii2-excel/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

yii2,excel
==========

[](#yii2excel)

Yii2 excel 导入，导出扩展， 本扩展基于phpexcel的升级版本 [phpspreadsheet](http://github.com/phpoffice/phpspreadsheet). 主要有以下功能：

导出
--

[](#导出)

- 基于activeDataPrivoder生成Excel
- 基于ActiveRecrod生成Excel
- 基于二维数组生成Excel
- 模型中定义show(),可对输出值进行转换
- 指定导出字段
- 支持导出model的关联数据
- 自定义输出版本

导入
--

[](#导入)

- 直接生成ActiveRecrod的模型
- 按表头生成数组
- 指定表头位置
- 可按模型attribute导入
- 按attributeLabel中文导入

安装
--

[](#安装)

---

您可以通过 [composer](http://getcomposer.org/download/) 安装.

本项目在github的地址是

运行
--

[](#运行)

```
php composer.phar require --prefer-dist ciniran/yii2-excel "*"

```

or add

```
"ciniran/yii2-excel": "*"

```

to the require section of your `composer.json` file.

用法
--

[](#用法)

---

下面是一些简单示例：

### DataPrivoder to excel:

[](#dataprivoder-to-excel)

```
      $dataPrivoder = new ActiveDataProvider([
            'query' => User::find(),
        ]);
        $excel = new SaveExcel([
            'dataProvider' => $dataPrivoder,
          //'show' => true,  //是否对值进行转换
            'fields' => 'email,username', //or ['email,username'] 限制导出的列
            'format' => SaveExcel::XLXS, 输出版本
            'all' => true,  //导出全部数据
            'relation' => false, //模型关系数据
        ]);
        $excel->dataProviderToExcel();

```

### ActiveRecord to excel:

[](#activerecord-to-excel)

```
        $models = User::find()->all();
        $excel = new SaveExcel([
            'models' => $models,
            // 'show' => true,
        ]);
        $excel->modelsToExcel();

```

### Array to excel

[](#array-to-excel)

```
     $array = [
            [
                'name'=>'tom',
                'age'=>18,
            ],
            [
                'name'=>'jerry',
                'age'=>19,
            ],
        ];
        $excel = new SaveExcel([
            'array' => $array,
            'headerDataArray' => ['name', 'age'],
        ]);
        $excel->arrayToExcel();

```

### Read excel file to array

[](#read-excel-file-to-array)

```
       $path = 'user.xlsx';
        $excel = new ReadExcel([
            'path' => $path,
            'head' => true,
            'headLine' => 1,
        ]);
        $data = $excel->getArray();

```

### Read excel file to models

[](#read-excel-file-to-models)

```
        $path = 'user.xlsx';
        $excel = new ReadExcel([
            'path' => $path,
            'head' => true,
            'headLine' => 1,
            'class' => 'common\\models\\User',
            'useLabel' => true,
        ]);
        $models = $excel->getModels();

```

下方是英文说明
=======

[](#下方是英文说明)

yii2,excel
==========

[](#yii2excel-1)

excel tools

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist ciniran/yii2-excel "*"

```

or add

```
"ciniran/yii2-excel": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your code by :

### DataPrivoder to excel:

[](#dataprivoder-to-excel-1)

```
      $dataPrivoder = new ActiveDataProvider([
            'query' => User::find(),
        ]);
        $excel = new SaveExcel([
            'dataProvider' => $dataPrivoder,
          //'show' => true,
            'fields' => 'email,username', //or ['email,username']
            'format' => SaveExcel::XLXS,
            'all' => true,
            'relation' => false, //模型关系数据
        ]);
        $excel->dataProviderToExcel();

```

### ActiveRecord to excel:

[](#activerecord-to-excel-1)

```
        $models = User::find()->all();
        $excel = new SaveExcel([
            'models' => $models,
            // 'show' => true,
        ]);
        $excel->modelsToExcel();

```

### Array to excel

[](#array-to-excel-1)

```
     $array = [
            [
                'name'=>'tom',
                'age'=>18,
            ],
            [
                'name'=>'jerry',
                'age'=>19,
            ],
        ];
        $excel = new SaveExcel([
            'array' => $array,
            'headerDataArray' => ['name', 'age'],
        ]);
        $excel->arrayToExcel();

```

### Read excel file to array

[](#read-excel-file-to-array-1)

```
       $path = 'user.xlsx';
        $excel = new ReadExcel([
            'path' => $path,
            'head' => true,
            'headLine' => 1,
        ]);
        $data = $excel->getArray();

```

### Read excel file to models

[](#read-excel-file-to-models-1)

```
        $path = 'user.xlsx';
        $excel = new ReadExcel([
            'path' => $path,
            'head' => true,
            'headLine' => 1,
            'class' => 'common\\models\\User',
            'useLabel' => true,
        ]);
        $models = $excel->getModels();

```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

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

2799d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17701981?v=4)[Xiebo](/maintainers/ciniran)[@ciniran](https://github.com/ciniran)

---

Top Contributors

[![ciniran](https://avatars.githubusercontent.com/u/17701981?v=4)](https://github.com/ciniran "ciniran (6 commits)")

---

Tags

yii2extension

### Embed Badge

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

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

###  Alternatives

[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

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