maatwebsite/Excel 3.1怎么分块导出?

我现在想把数据通过chunk分块丢到队列里 然后根据块的大小在队列对excel进行一行行进行写入,有例子吗?

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 5

3.1不能这么用,我也找了好久,问了同事才知道它自带一个query函数,模型::query 就是分块查询了,在官方文档的From Query位置

2年前 评论

<?php

namespace App\Exports;

use App\Models\User;
use Illuminate\Support\Facades\Log;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class UsersExport implements FromQuery,WithHeadings,WithMapping
{

public function __construct($where){
    $this->where = $where;
}

//laravel Excel的分块处理
public function query()
{
    $where = $this->where;
    return User::query()->where($where);
}

//标题
public function headings(): array
{
    $header = [
        'name'=>'姓名',
        'job'=>'职务',
        'craft'=>'工种',
        'politics_status'=>'政治面貌',
        'phone'=>'联系电话',
    ];

    return $header;

}

//处理数据
public function map($row): array
{
    $data = [
        'name'=>$row->name,
        'job'=>$row->job,
        'craft'=>$row->craft,
        'politics_status'=>$row->politics_status,
        'phone'=>$row->phone,
    ];
    return $data;
}

}

贴上实例,控制器里面调用还是一样的 return Excel::download(new UsersExport($data), ‘invoices.xlsx’);

2年前 评论
Toml 2年前

通过查询导出这种,如果查询出来的块数据,需要继续处理(比如再返回一个需要计算的属性:某某数量),该怎么写 :neutral_face:

9个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!