PHPackages                             dcat-x/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. [PDF &amp; Document Generation](/categories/documents)
4. /
5. dcat-x/easy-excel

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

dcat-x/easy-excel
=================

A simple and elegant Excel read/write library based on OpenSpout, with minimal memory usage

v1.0.2(5mo ago)14411MITPHPPHP ^8.2CI passing

Since Jan 12Pushed 5mo agoCompare

[ Source](https://github.com/dcat-x/easy-excel)[ Packagist](https://packagist.org/packages/dcat-x/easy-excel)[ Docs](https://github.com/dcat-x/easy-excel)[ GitHub Sponsors](https://github.com/sponsors/dcat-x)[ RSS](/packages/dcat-x-easy-excel/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependencies (4)Versions (4)Used By (1)

Easy Excel
==========

[](#easy-excel)

[![Tests](https://github.com/dcat-x/easy-excel/workflows/Tests/badge.svg)](https://github.com/dcat-x/easy-excel/actions)[![Latest Version on Packagist](https://camo.githubusercontent.com/a532c159d501ce427c6675fc0b3528945c836aca9384485b5ac7b0e10b674aaf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646361742d782f656173792d657863656c2e737667)](https://packagist.org/packages/dcat-x/easy-excel)[![Total Downloads](https://camo.githubusercontent.com/496224bc7b74219adcd1a848a4372fbe94a9c7051192ff064067f03b6d6c55ac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646361742d782f656173792d657863656c2e737667)](https://packagist.org/packages/dcat-x/easy-excel)[![PHP Version](https://camo.githubusercontent.com/2df76cc624639921b9c2b3a3a24b42cb4080a837402951482fb4517c3e2e1599/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646361742d782f656173792d657863656c2e737667)](https://packagist.org/packages/dcat-x/easy-excel)[![License](https://camo.githubusercontent.com/e0a58e1baaece41f2cd9e4c899262b95782aa0e3d8dd60be2fb13c72eb5fb134/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f646361742d782f656173792d657863656c2e737667)](https://github.com/dcat-x/easy-excel/blob/main/LICENSE)

基于 [OpenSpout](https://github.com/openspout/openspout) 封装的 Excel 读写工具，内存占用极低。

[安装](#%E5%AE%89%E8%A3%85) | [使用](#%E4%BD%BF%E7%94%A8) | [更新日志](CHANGELOG.md) | [贡献指南](CONTRIBUTING.md)

---

特性
--

[](#特性)

- 读写 Excel 文件，内存占用极低
- 支持 `xlsx`、`csv`、`ods` 格式
- 分块处理，轻松应对大文件
- 集成 Flysystem，灵活存储
- 支持自定义表头和多工作表
- 简洁直观的 API

安装
--

[](#安装)

```
composer require dcat-x/easy-excel
```

### 环境要求

[](#环境要求)

- PHP &gt;= 8.2
- PHP 扩展：`zip`、`xmlreader`

使用
--

[](#使用)

### 导出

[](#导出)

#### 下载文件

[](#下载文件)

```
use Dcat\EasyExcel\Excel;

$data = [
    ['id' => 1, 'name' => 'Tom', 'email' => 'tom@example.com'],
    ['id' => 2, 'name' => 'Jerry', 'email' => 'jerry@example.com'],
];

// 自定义表头
$headings = ['id' => 'ID', 'name' => '姓名', 'email' => '邮箱'];

Excel::export($data)->headings($headings)->download('users.xlsx');
Excel::export($data)->headings($headings)->download('users.csv');
Excel::export($data)->headings($headings)->download('users.ods');
```

#### 保存到服务器

[](#保存到服务器)

```
use Dcat\EasyExcel\Excel;
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;

// 保存到本地路径
Excel::export($data)->store('/tmp/users.xlsx');

// 使用 Flysystem
$filesystem = new Filesystem(new LocalFilesystemAdapter(__DIR__));
Excel::export($data)->disk($filesystem)->store('users.xlsx');
```

#### 获取文件内容

[](#获取文件内容)

```
use Dcat\EasyExcel\Excel;

$xlsx = Excel::xlsx($data)->raw();
$csv = Excel::csv($data)->raw();
$ods = Excel::ods($data)->raw();
```

### 导入

[](#导入)

#### 读取所有数据

[](#读取所有数据)

```
use Dcat\EasyExcel\Excel;

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

$allSheets = Excel::import('/tmp/users.xlsx')->headings($headings)->toArray();
// 返回: ['Sheet1' => [['id' => 1, 'name' => 'Tom', ...], ...]]
```

#### 读取指定工作表

[](#读取指定工作表)

```
use Dcat\EasyExcel\Excel;

// 第一个工作表
$data = Excel::import('/tmp/users.xlsx')->first()->toArray();

// 最后活动的工作表
$data = Excel::import('/tmp/users.xlsx')->active()->toArray();

// 按名称或索引获取
$data = Excel::import('/tmp/users.xlsx')->sheet('Sheet1')->toArray();
$data = Excel::import('/tmp/users.xlsx')->sheet(0)->toArray();
```

#### 遍历工作表

[](#遍历工作表)

```
use Dcat\EasyExcel\Excel;
use Dcat\EasyExcel\Contracts\Sheet;
use Dcat\EasyExcel\Support\SheetCollection;

Excel::import('/tmp/users.xlsx')->each(function (Sheet $sheet) {
    $name = $sheet->getName();
    $index = $sheet->getIndex();

    $sheet->chunk(1000, function (SheetCollection $collection) {
        foreach ($collection as $row) {
            // 处理每一行
        }
    });
});
```

#### 分块处理

[](#分块处理)

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

// 每次处理 1000 行，适合大文件
Excel::import('/tmp/users.xlsx')
    ->first()
    ->chunk(1000, function (SheetCollection $collection) {
        $data = $collection->toArray();
        // 批量处理数据...
    });
```

测试
--

[](#测试)

```
composer test
```

更新日志
----

[](#更新日志)

详见 [CHANGELOG](CHANGELOG.md)。

贡献
--

[](#贡献)

详见 [CONTRIBUTING](CONTRIBUTING.md)。

许可证
---

[](#许可证)

MIT 许可证，详见 [LICENSE](LICENSE)。

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance71

Regular maintenance activity

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 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

Every ~0 days

Total

3

Last Release

161d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

exportexcelxlsxcsvwriterreaderspreadsheetodsimportopenspout

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[openspout/openspout

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

1.2k65.5M209](/packages/openspout-openspout)[avadim/fast-excel-reader

Lightweight and very fast XLSX Excel Spreadsheet and CSV Reader in PHP

106693.8k9](/packages/avadim-fast-excel-reader)[nuovo/spreadsheet-reader

Spreadsheet reader library for Excel, OpenOffice and structured text files

668883.3k8](/packages/nuovo-spreadsheet-reader)[dcat/easy-excel

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

155384.9k28](/packages/dcat-easy-excel)[jgrygierek/batch-entity-import-bundle

Importing entities with preview and edit features for Symfony.

101.1M1](/packages/jgrygierek-batch-entity-import-bundle)[jgrygierek/sonata-batch-entity-import-bundle

Importing entities with preview and edit features for Sonata Admin.

10955.3k](/packages/jgrygierek-sonata-batch-entity-import-bundle)

PHPackages © 2026

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