laravel Excel export 问题请教

在使用过程中 php版本7.2
使用格式csv 合并单元格不生效(styles 实现) 使用格式xls 则是乱码
php7.3 使用格式csv 合并单元格不生效(styles 实现) 使用格式xls 则可以生效
请问有大佬知道什么原因吗?谢谢Thanks♪(・ω・)ノ

部分代码附下:

<?php

namespace App\Exports\Banker\Traffic;

use App\Http\Controllers\JsLibController;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\WithTitle;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;

class TrafficProcurementExport implements FromCollection, WithHeadings, WithMapping,WithTitle,WithColumnWidths,WithStyles
{
    protected $data;
    protected $title;
    protected $time;
    protected $count;
    protected $count_order_amount;
    protected $trafficResourceTypeContent;

    public function __construct($data,$title = '',$time,$count,$count_order_amount,$trafficResourceTypeContent)
    {
        $this->data = $data;
        $this->title = $title;
        $this->time = $time;
        $this->count = $count;
        $this->count_order_amount = $count_order_amount;
        $this->trafficResourceTypeContent = $trafficResourceTypeContent;
    }

    /**
     * 样式设置
     */
    public function styles(Worksheet $sheet){
        $sheet->getDefaultRowDimension()->setRowHeight(22);//设置行高
        $sheet->getStyle('A1:U1')->getAlignment()->setVertical('center');//垂直居中
        $sheet->getStyle('A1:U1')->applyFromArray(['alignment' => ['horizontal' => 'center']]);//设置水平居中
        $sheet->getStyle('A1:U1')->applyFromArray(['font' => ['bold' => true, 'color' => ['rgb' => '0072ff']]]);//字体设置
        $sheet->mergeCells('A1:U1'); //合并单元格
        $sheet->mergeCells('C2:I2'); //合并单元格
        $sheet->mergeCells('J2:K2'); //合并单元格
        $sheet->mergeCells('M2:R2'); //合并单元格
    }
}
 return Excel::download(new TrafficProcurementExport(collect($resultArray),'测试',$time,count($result),$count_order_amount,$trafficResourceTypeContent),'traffic_procurement.csv');
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 1

同问,这个搞了很久但是都不生效也不知道是配置问题还是什么。

3年前 评论

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