laravel-enso/excel
Composer 安装命令:
composer require laravel-enso/excel
包简介
Excel for Laravel Enso
关键字:
README 文档
README
Description
Excel provides a small contract-based .xlsx export service for Laravel and Laravel Enso.
The package delegates spreadsheet writing to OpenSpout and keeps the exporter API intentionally simple: an exporter object declares the workbook filename, the sheet names, the heading row for each sheet, and the data rows for each sheet.
It is used in Enso to generate downloadable or persisted Excel files from domain-specific exporter classes without coupling those exporters to a concrete writer implementation.
Installation
Install the package:
composer require laravel-enso/excel
The package does not require service provider registration.
To use it, create a class that implements LaravelEnso\Excel\Contracts\ExportsExcel, then pass that exporter to LaravelEnso\Excel\Services\ExcelExport.
If you want the generated file saved under a custom storage folder, also implement LaravelEnso\Excel\Contracts\SavesToDisk.
Features
- Exports
.xlsxfiles through OpenSpout. - Supports multi-sheet workbooks.
- Uses a small
ExportsExcelcontract for exporter classes. - Can stream files inline as downloads.
- Can save files to disk and return their storage path.
- Supports custom storage folders through
SavesToDisk.
Usage
Define an exporter:
use LaravelEnso\Excel\Contracts\ExportsExcel; class ContractorStock implements ExportsExcel { public function filename(): string { return 'stock_report.xlsx'; } public function heading(string $sheet): array { return match ($sheet) { 'stock' => ['Product', 'Quantity'], 'history' => ['Date', 'Product', 'Quantity'], }; } public function rows(string $sheet): array { return match ($sheet) { 'stock' => [['Panel', 12]], 'history' => [['2026-04-18', 'Panel', 12]], }; } public function sheets(): array { return ['stock', 'history']; } }
Stream the export to the browser:
use LaravelEnso\Excel\Services\ExcelExport; return (new ExcelExport(new ContractorStock()))->inline();
Save it to disk:
$path = (new ExcelExport(new ContractorStock()))->save();
Use a custom folder by implementing SavesToDisk:
use LaravelEnso\Excel\Contracts\ExportsExcel; use LaravelEnso\Excel\Contracts\SavesToDisk; class OrderExport implements ExportsExcel, SavesToDisk { public function folder(): string { return 'exports/orders'; } }
::: warning Note
Every sheet name returned by sheets() must have a matching heading() and rows() implementation.
When the exporter does not implement SavesToDisk, files are written under the default temp storage folder.
:::
API
Exporter Contracts
LaravelEnso\Excel\Contracts\ExportsExcelLaravelEnso\Excel\Contracts\SavesToDisk
ExportsExcel requires:
filename(): stringheading(string $sheet): arrayrows(string $sheet): arraysheets(): array
SavesToDisk adds:
folder(): string
Export Service
LaravelEnso\Excel\Services\ExcelExport
Public methods:
__construct(ExportsExcel $exporter)inline(): BinaryFileResponsesave(): string
Behavior:
- creates the workbook on disk first
- writes one worksheet per value returned by
sheets() - writes the heading row first, then all data rows
- downloads and deletes the file after send when using
inline()
Exception
LaravelEnso\Excel\Exceptions\ExcelExport
Currently exposes:
missingInterface()
Depends On
Framework dependency:
External dependency:
Contributions
are welcome. Pull requests are great, but issues are good too.
Thank you to all the people who already contributed to Enso!
laravel-enso/excel 适用场景与选型建议
laravel-enso/excel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39.6k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 10 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「excel」 「laravel」 「laravel-enso」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 laravel-enso/excel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laravel-enso/excel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 laravel-enso/excel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Enums for Laravel Enso
Company management dependency for Laravel Enso
Person management for Laravel Enso
Image transformer dependency for Laravel Enso
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
Search and interval helpers for Laravel Enso
统计信息
- 总下载量: 39.6k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-10-02