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');
同问,这个搞了很久但是都不生效也不知道是配置问题还是什么。