PHPackages                             purocean/php-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. purocean/php-excel

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

purocean/php-excel
==================

方便快捷的 Excel 导出导入类

v1.2.1(8y ago)076021MITPHPPHP &gt;=5.6.0

Since Feb 4Pushed 8y ago1 watchersCompare

[ Source](https://github.com/purocean/php-excel)[ Packagist](https://packagist.org/packages/purocean/php-excel)[ Docs](https://github.com/purocean/php-excel)[ RSS](/packages/purocean-php-excel/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (1)Versions (12)Used By (1)

php-excel
=========

[](#php-excel)

方便快捷的 Excel 导出导入类,就俩静态方法

安装
==

[](#安装)

composer require purocean/php-excel

简单上手
----

[](#简单上手)

### 导出

[](#导出)

```
use YExcel\Excel;

// 从数据库之类得到数据，数组或可遍历的生成器，支持使用闭包灵活配置每一个单元格
$data = [
    ["a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10"],
    ["b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10"],
    ["c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10"],
    [
        function ($sheet, $colNum, $rowNum) {
            $sheet->setCellValueByColumnAndRow($colNum, $rowNum, "d1");
            $fill = $sheet->getStyleByColumnAndRow($colNum, $rowNum)->getFill();
            $fill->setFillType('solid');
            $fill->getStartColor()->setARGB('FFFFEB18');
        },
        function ($sheet, $colNum, $rowNum) {
            $sheet->setCellValueByColumnAndRow($colNum, $rowNum, "d2");
            $fill = $sheet->getStyleByColumnAndRow($colNum, $rowNum)->getFill();
            $fill->setFillType('solid');
            $fill->getStartColor()->setARGB('FFFFEB18');
        },
        function ($sheet, $colNum, $rowNum) {
            $sheet->setCellValueByColumnAndRow($colNum, $rowNum, "d3");
            $fill = $sheet->getStyleByColumnAndRow($colNum, $rowNum)->getFill();
            $fill->setFillType('solid');
            $fill->getStartColor()->setARGB('FFFFEB18');
        },
        function ($sheet, $colNum, $rowNum) {
            $sheet->setCellValueByColumnAndRow($colNum, $rowNum, "d4");
            $fill = $sheet->getStyleByColumnAndRow($colNum, $rowNum)->getFill();
            $fill->setFillType('solid');
            $fill->getStartColor()->setARGB('FFFFEB18');
        },
        function ($sheet, $colNum, $rowNum) {
            $sheet->setCellValueByColumnAndRow($colNum, $rowNum, "d5");
            $fill = $sheet->getStyleByColumnAndRow($colNum, $rowNum)->getFill();
            $fill->setFillType('solid');
            $fill->getStartColor()->setARGB('FFFFEB18');
        },
        function ($sheet, $colNum, $rowNum) {
            $sheet->setCellValueByColumnAndRow($colNum, $rowNum, "d6");
            $fill = $sheet->getStyleByColumnAndRow($colNum, $rowNum)->getFill();
            $fill->setFillType('solid');
            $fill->getStartColor()->setARGB('FFFFEB18');
        },
        function ($sheet, $colNum, $rowNum) {
            $sheet->setCellValueByColumnAndRow($colNum, $rowNum, "d7");
            $fill = $sheet->getStyleByColumnAndRow($colNum, $rowNum)->getFill();
            $fill->setFillType('solid');
            $fill->getStartColor()->setARGB('FFFFEB18');
        },
        function ($sheet, $colNum, $rowNum) {
            $sheet->setCellValueByColumnAndRow($colNum, $rowNum, "d8");
            $fill = $sheet->getStyleByColumnAndRow($colNum, $rowNum)->getFill();
            $fill->setFillType('solid');
            $fill->getStartColor()->setARGB('FFFFEB18');
        },
        function ($sheet, $colNum, $rowNum) {
            $sheet->setCellValueByColumnAndRow($colNum, $rowNum, "d9");
            $fill = $sheet->getStyleByColumnAndRow($colNum, $rowNum)->getFill();
            $fill->setFillType('solid');
            $fill->getStartColor()->setARGB('FFFFEB18');
        },
        function ($sheet, $colNum, $rowNum) {
            $sheet->setCellValueByColumnAndRow($colNum, $rowNum, "d10");
            $fill = $sheet->getStyleByColumnAndRow($colNum, $rowNum)->getFill();
            $fill->setFillType('solid');
            $fill->getStartColor()->setARGB('FFFFEB18');
        }
    ],
];

$template = 'template.xlsx'; // 模板文件，如果不提供则新建一个 xlsx 文件

// 给浏览器发送下载头
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename=sites_export.xlsx');
header('Cache-Control: max-age=0');

// 默认跳过第一行表头
// 更多使用请查看 src\Excel 注释
Excel::put('php://output', $data, ['tplFile' => $template]);

// 多个 sheet 导出
Excel::put('php://output', [1 => $data], [multiSheet => [1 => 'test11']]);
```

### 导入

[](#导入)

```
use YExcel\Excel;

// 默认跳过第一行表头
// 更多使用请查看 src\Excel 注释
foreach (Excel::get('file.xlsx') as $row) {
    var_dump($row);
    // 写入数据库之类
}
```

测试
--

[](#测试)

```
cd test
php test.php
```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 80% 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 ~28 days

Recently: every ~46 days

Total

11

Last Release

3150d ago

Major Versions

v0.2.0 → v1.0.02017-05-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7115690?v=4)[洋子](/maintainers/purocean)[@purocean](https://github.com/purocean)

---

Top Contributors

[![purocean](https://avatars.githubusercontent.com/u/7115690?v=4)](https://github.com/purocean "purocean (12 commits)")[![dark-wind](https://avatars.githubusercontent.com/u/15257951?v=4)](https://github.com/dark-wind "dark-wind (3 commits)")

---

Tags

phpexcelxlsxlsxoffice

### Embed Badge

![Health badge](/badges/purocean-php-excel/health.svg)

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

###  Alternatives

[openspout/openspout

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

1.2k65.5M217](/packages/openspout-openspout)

PHPackages © 2026

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