PHPackages                             zhanxin/easy-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. [File &amp; Storage](/categories/file-storage)
4. /
5. zhanxin/easy-excel

ActiveLibrary[File &amp; Storage](/categories/file-storage)

zhanxin/easy-excel
==================

使用简单实用的语义化接口快速读写Excel文件

02PHP

Since Dec 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/caserwiki/easy-excel)[ Packagist](https://packagist.org/packages/zhanxin/easy-excel)[ RSS](/packages/zhanxin-easy-excel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

EASY EXCEL
==========

[](#easy-excel)

`Easy Excel`是一个基于 [box/spout](https://github.com/box/spout) 封装的Excel读写工具，可以帮助开发者更快速更轻松地读写Excel文件， 并且无论读取多大的文件只需占用极少的内存。

> 由于`box/spout`只支持读写`xlsx`、`csv`、`ods`等类型文件，所以本项目目前也仅支持读写这三种类型的文件。

文档
--

[](#文档)

[文档](https://jqhph.github.io/easy-excel/)

环境
--

[](#环境)

- PHP &gt;= 7.1
- PHP extension php\_zip
- PHP extension php\_xmlreader
- box/spout &gt;= 3.0
- league/flysystem &gt;= 1.0

安装
--

[](#安装)

```
composer require zhanxin/easy-excel
```

### 快速开始

[](#快速开始)

#### 导出

[](#导出)

下载

```
use Zx\EasyExcel\Excel;

$array = [
    ['id' => 1, 'name' => 'Brakus', 'email' => 'treutel@eg.com', 'created_at' => '...'],
    ...
];

$headings = ['id' => 'ID', 'name' => '名称', 'email' => '邮箱'];

// xlsx
Excel::export($array)->headings($headings)->download('users.xlsx');

// csv
Excel::export($array)->headings($headings)->download('users.csv');

// ods
Excel::export($array)->headings($headings)->download('users.ods');
```

保存

```
use Zx\EasyExcel\Excel;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;

$array = [...];

// 保存到当前服务器
Excel::export($array)->store('/tmp/users.xlsx');

// 使用 filesystem
$adapter = new Local(__DIR__);

$filesystem = new Filesystem($adapter);

Excel::export($array)->disk($filesystem)->store('users.xlsx');
```

获取文件内容

```
use Zx\EasyExcel\Excel;

$array = [...];

$xlsxContents = Excel::xlsx($array)->raw();

$csvContents = Excel::csv($array)->raw();

$odsContents = Excel::ods($array)->raw();
```

更多导出功能请参考[文档](https://jqhph.github.io/easy-excel/docs/master/export.html)。

#### 导入

[](#导入)

读取所有表格数据

```
use Zx\EasyExcel\Excel;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;

$headings = ['id', 'name', 'email'];

// 导入xlsx
$allSheets = Excel::import('/tmp/users.xlsx')->headings($headings)->toArray();

// 使用filesystem
$adapter = new Local(__DIR__);

$filesystem = new Filesystem($adapter);

$allSheets = Excel::import('users.xlsx')->disk($filesystem)->headings($headings)->toArray();

print_r($allSheets); // ['Sheet1' => [['id' => 1, 'name' => 'Brakus', 'email' => 'treutel@eg.com', 'created_at' => '...']]]
```

遍历表格

```
use Zx\EasyExcel\Excel;
use Zx\EasyExcel\Contracts\Sheet as SheetInterface;
use Zx\EasyExcel\Support\SheetCollection;

// 导入xlsx
Excel::import('/tmp/users.xlsx')->each(function (SheetInterface $sheet) {
    // 获取表格名称，如果是csv文件，则此方法返回空字符串
    $sheetName = $sheet->getName();

    // 表格序号，从 0 开始
    $sheetIndex = $sheet->getIndex();

    // 是否是最后一次保存前打开的表格
    $isActive = $sheet->isActive();

    // 分块处理表格数据
    $sheet->chunk(100, function (SheetCollection $collection) {
        $chunkArray = $collection->toArray();

        print_r($chunkArray); // [['id' => 1, 'name' => 'Brakus', 'email' => 'treutel@eg.com', 'created_at' => '...']]
    });

});
```

获取指定表格内容

```
use Zx\EasyExcel\Excel;
use Zx\EasyExcel\Support\SheetCollection;

// 获取第一个表格内容
$firstSheet = Excel::import('/tmp/users.xlsx')->first()->toArray();

// 获取最后一次保存前打开的表格内容
$activeSheet = Excel::import('/tmp/users.xlsx')->active()->toArray();

// 获取指定名称或序号的表格内容
$sheet = Excel::import('/tmp/users.xlsx')->sheet('Sheet1')->toArray();
$sheet = Excel::import('/tmp/users.xlsx')->sheet(0)->toArray();

// 分块处理表格内容
Excel::import('/tmp/users.xlsx')
    ->first()
    ->chunk(1000, function (SheetCollection $collection) {
        $collection = $collection->keyBy('id');
    });
```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8da510ed8ca69d8da0042bcbf167dda6979a1142aec3e95e929a4090d934c909?d=identicon)[caserwiki](/maintainers/caserwiki)

---

Top Contributors

[![caserwiki](https://avatars.githubusercontent.com/u/52273420?v=4)](https://github.com/caserwiki "caserwiki (2 commits)")

### Embed Badge

![Health badge](/badges/zhanxin-easy-excel/health.svg)

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

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M124](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

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