zuko/flex2cell
Composer 安装命令:
composer require zuko/flex2cell
包简介
A flexible and efficient library for exporting data to Excel (XLS, XLSX) with support for mappings, formatters, and handling large datasets. Working with less dependencies, avoid future breaks & conclusions.
README 文档
README
Flex2Cell is a flexible and efficient PHP library for exporting data to Excel (XLS, XLSX) with support for headers, data mappings, formatters, and handling large datasets. It's dependent on the PhpSpreadsheet library.
Features
- Export data to Excel in XLS or XLSX format using Microsoft's format.
- Supports data from collections, Eloquent models, or multi-dimensional arrays alternative to
Eloquent\Collection::toArray()format. - Allows custom column headers and mapping between data fields and Excel columns.
- Includes value formatting using transformers (e.g., formatting dates, transforming IDs to names).
- Supports hidden fields, meaning you can choose which fields should not appear in the export.
- Provides meta settings for the output file (e.g., author, title).
- Efficient memory usage when exporting large datasets.
- Supports partial exports with
replaceorappendmodes, allowing export in chunks. - Custom column and row merging rules.
Installation
To install the library, add it to your project via Composer:
composer require zuko/flex2cell
Usage
Simple Export Example
use Zuko\Flex2Cell\ExcelExporter; $data = // your data here... ExcelExporter::export($data, 'export.xlsx', [ 'headers' => ['#', 'Name', 'Product Group', 'Owner Name', 'Business Type', 'District', 'Commune'], 'mapping' => [ 'id' => '#', 'name' => 'Name', 'product_group' => 'Product Group', 'owner_name' => 'Owner Name', 'owner_business_type' => 'Business Type', 'district.name' => 'District', 'village.name' => 'Commune', ], 'formatters' => [ 'owner_business_type' => new CustomFormatter(), 'district.name' => 'FullyQualifiedFormatterClassName', ], 'columnMergeRules' => [ ['start' => 'district.name', 'end' => 'village.name', 'label' => 'Address', 'shiftDown' => true] ], 'rowMergeRules' => [ 'product_group', 'owner_name', 'owner_business_type' ] ]);
Fluent API Usage
You can also use a fluent interface for more control:
use Zuko\Flex2Cell\ExcelExporter; // custom formatter class class BusinessTypeFormatter implements Zuko\Flex2Cell\Contracts\FormatterInterface { public function formatValue($value) { return ucwords(str_replace('_', ' ', $value)); } } $data = // your data here... ExcelExporter::make() ->setData($data) ->setHeaders(['ID', 'Name', 'Product Area', 'Nursery Area', 'Category']) ->setMapping([ 'id' => 'ID', 'name' => 'Name', 'product_area' => 'Product Area', 'nursery_area' => 'Nursery Area', 'category.name' => 'Category' ]) ->setFormatters([ 'category.name' => fn($value) => ucfirst($value), 'owner_business_type' => new CustomFormatter(), ]) ->setColumnMergeRules([ ['start' => 'C', 'end' => 'D', 'label' => 'AREA'] ]) ->setRowMergeRules([ 'E' => ['field' => 'category.name'] ]) ->export('export.xlsx');
zuko/flex2cell 适用场景与选型建议
zuko/flex2cell 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 40 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 10 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 zuko/flex2cell 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zuko/flex2cell 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 40
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-13