wuxuejian/laravel-excel
Composer 安装命令:
composer require wuxuejian/laravel-excel
包简介
Laravel-Excel is based on Spartner NL/Lavel Excel code and switches to an xlswriter extension. If your project is using SparnerNL/Lavel Excel and there are big data export performance issues, and you don't want to modify a lot of code, then the current package may be very suitable for you.
README 文档
README
xlswriter是一款高性能的php excel读写扩展,Laravel-excel基于SpartnerNL/Laravel-Excel代码上,切换成xlswriter扩展。 如果您的项目使用的是SpartnerNL/Laravel-Excel并且出现大数据导出性能问题,你不想修改大量的代码,那么当前的包可能会很适合你。 当然目前的包不可能百分之百兼容所有功能,目前只实现了部分基础的功能。
如果本扩展帮助到了你 欢迎star。
如果本扩展有任何问题或有其他想法 欢迎提 issue与pull request。
Laravel-excel使用教程
环境要求
xlswriter>= 1.3.7PHP>= 8.0 安装请按照XlsWriter的官方文档:安装教程
安装
composer require mckue/laravel-excel
发布mckue-excel.php配置文件:
php artisan vendor:publish --provider="Mckue\Excel\ExcelServiceProvider" --tag=config
1.命令
1.1 查看xlswriter扩展是否正常安装
php artisan php-ext-xlswriter:status
展示信息如下:
info:
+---------+---------------------------------------------+
| version | 1.0 |
| author | mckue<https://github.com/carlin-rj> |
| docs | https://github.com/carlin-rj/laravel-excel |
+---------+---------------------------------------------+
XlsWriter extension status:
+-------------------------------+----------------------------+
| loaded | yes |
| xlsWriter author | Jiexing.Wang (wjx@php.net) |
| xlswriter support | enabled |
| Version | 1.3.7 |
| bundled libxlsxwriter version | 1.0.0 |
| bundled libxlsxio version | 0.2.27 |
+-------------------------------+----------------------------+
如您的信息展示如上所示,证明您的cli环境下本扩展可用。
1.快速开始
<?php
namespace App\Exports;
use Mckue\Excel\Concerns\FromArray;
class UserExport implements FromArray
{
/**
* @return array */
public function array() : array
{
return [ ['哈哈', 'aaa'],
['哈哈', 'aaa'],
['哈哈', 'aaa'],
['哈哈', 'aaa']
];
}
/**
* @return array
*/
public function headers() : array {
return [];
}
}
🔥 在您的控制器中,您现在可以调用此导出:
<?php
namespace App\Http\Controllers;
use App\Exports\UsersExport;
use Mckue\Excel\Facades\Excel;
class UsersController extends Controller
{
public function export()
{
return Excel::download(new UserExport, 'users.xlsx');
}
}
最后添加一条能够访问导出的路由:
Route::get('users/export/', [UsersController::class, 'export']);
2.导出集合
InvoicesExport创建一个名为的新类app/Exports:
namespace App\Exports;
use App\Invoice;
use Mckue\Excel\Concerns\FromCollection;
class InvoicesExport implements FromCollection
{
public function collection()
{
return Invoice::all();
}
}
在您的控制器中,我们现在可以下载此导出:
public function export()
{
return Excel::download(new InvoicesExport, 'invoices.xlsx');
}
您可以选择传入是否输出标头和自定义响应标头:
public function export()
{
return Excel::download(new InvoicesExport, 'invoices.xlsx', true, ['X-Vapor-Base64-Encode' => 'True']);
}
或者将其存储在磁盘上(例如 s3):
public function storeExcel()
{
return Excel::store(new InvoicesExport, 'invoices.xlsx', 's3');
}
3.使用自定义结构
namespace App\Exports;
use App\Invoice;
use Mckue\Excel\Concerns\FromCollection;
class InvoicesExport implements FromCollection
{
public function collection()
{
return new Collection([
[1, 2, 3],
[4, 5, 6]
]);
}
}
4.使用查询
namespace App\Exports;
use App\Invoice;
use Mckue\Excel\Concerns\FromQuery;
use Mckue\Excel\Concerns\Exportable;
class InvoicesExport implements FromQuery
{
use Exportable;
public function query()
{
return Invoice::query();
}
}
5.使用迭代器
namespace App\Exports;
use App\Invoice;
use Mckue\Excel\Concerns\FromIterator;
use Mckue\Excel\Concerns\Exportable;
class InvoicesExport implements FromIterator
{
use Exportable;
public function iterator(): Iterator
{
...
}
}
在前面的示例中,我们使用Excel::download Facades来启动导出。
namespace App\Exports;
use App\Invoice;
use Mckue\Excel\Concerns\FromCollection;
use Mckue\Excel\Concerns\Exportable;
class InvoicesExport implements FromCollection
{
use Exportable;
public function collection()
{
return Invoice::all();
}
}
我们现在可以下载导出而无需Facades:
return (new InvoicesExport)->download('invoices.xlsx');
或者将其存储在磁盘上:
return (new InvoicesExport)->store('invoices.xlsx', 's3');
在此感谢 xlswriter的开发者viest 以及 SpartnerNL/Laravel-Excel的开发者。
如有什么问题可以及时反馈到github哦。
wuxuejian/laravel-excel 适用场景与选型建议
wuxuejian/laravel-excel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「excel」 「csv」 「import」 「export」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wuxuejian/laravel-excel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wuxuejian/laravel-excel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wuxuejian/laravel-excel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
Yii2 export extension
PHP Excel Library
laravel facade to read/write csv file
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-14