laravel excel导出调节列宽度,对某列中数据颜色处理

//$cellData 表格标题栏各名称数组
//$result  表格内容数组
//$items getForDataTable得到的表格数据


$result = array_merge($cellData,$result);
Excel::create('表格名' . date("Ymdhis"), function ($excel) use ($result, $items) {
$excel->sheet('表名', function ($sheet) use ($result, $items) {
       $sheet->rows($result)
->setWidth(array(//调整导出表格单元格宽度
'A' => '15%',
'B' => '13%',
'C' => '15%',
'D' => '15%',
));
for ($i = 0; $i < count($items); $i++) {//对某列中数据颜色处理
if ($items[$i]->flag > 0) {
$sheet->cell('E' . ($i + 2), function ($cell) use ($items) {
$cell->setFontColor('#c73333');
});
}
}
});
})->export('xls');
原文地址:https://www.cnblogs.com/webttt/p/9202024.html