wefabric/wp-excel
Composer 安装命令:
composer require wefabric/wp-excel
包简介
Implementation to use Excel export as a bulk action in the WordPress backend.
README 文档
README
Implementation to use Excel export as a bulk action in the WordPress backend. To use with the Wefabric themosis implementation. It uses the https://github.com/SpartnerNL/Laravel-Excel (v3.0) package.
Requirements
- Wefabric WP Support
- Themosis
Installation
Run the following command
composer require wefabric/wp-excel
Publish the config file
php console vendor:publish --tag=wp-excel
Usage
Every post type needs to be registered for export before usage. In the following example we will register the export class for a default WordPress post
- First you need to create the class which converts the posts data to an Illuminate Collection. To do this run the following command
php console make:export PostsExport
- Add the logic to export the WordPress posts to the Illuminate collection for example:
use Illuminate\Support\Collection; use Maatwebsite\Excel\Concerns\FromCollection; use Maatwebsite\Excel\Concerns\WithHeadings; use Wefabric\WPExcel\Concerns\WpPostsExcellable; class PostsExport implements FromCollection, WithHeadings, WpPostsExcellable { protected array $postIds = []; public function headings(): array { return [ 'Id', 'Title', ]; } /** * @return \Illuminate\Support\Collection */ public function collection(): Collection { $args = [ 'post_type' => 'post', 'posts_per_page' => -1, ]; if($this->postIds) { $args['post__in'] = $this->postIds; } $posts = get_posts($args); $collection = new Collection(); foreach ($posts as $post) { $collection->push([ 'Id' => $post->ID, 'Title' => $post->post_title, ]); } return $collection; } public function setPostIds(array $postIds) { $this->postIds = $postIds; } }
- Add the class to the wp-excel config file (config/wp-excel.php). Where 'post' is the post type name and the second parameter is the export class
return [ 'post_types' => [ 'post' => \App\Exports\PostsExport::class, ] ]
- Go to the WordPress backend (wp-admin/edit.php), select a post and run the bulk action.
Export formats
The default export format is 'XLSX'. To use a different export format change the 'default_format' in the wp-excel config file (config/wp-excel.php) to the correct format. The allowed export formats are located here: https://docs.laravel-excel.com/3.0/exports/export-formats.html
wefabric/wp-excel 适用场景与选型建议
wefabric/wp-excel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 01 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 wefabric/wp-excel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wefabric/wp-excel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-01-23