表頭設(shè)置
use Maatwebsite\Excel\Concerns\WithHeadings;
... ...
public function headings(): array
{
return array_column([
'序號(hào)','姓名'
]);
}
表標(biāo)題設(shè)置
use Maatwebsite\Excel\Concerns\WithTitle;
... ...
public function title(): string
{
return '匯總總表';
}
設(shè)置單元格
use Maatwebsite\Excel\Concerns\WithStyles;
... ...
public function styles(Worksheet $sheet)
{
// 凍結(jié)行
$sheet->freezePaneByColumnAndRow('1','2');
// 合并單元格
$sheet->mergeCells('A1:F1');
// 設(shè)置字體顏色和背景色
$sheet->getStyle('A1:J1')->applyFromArray([
'font' => [
'name' => '宋體',
'bold' => true,
'italic' => false,
'strikethrough' => false,
'color' => [
'rgb' => 'FFFFFF'
]
],
'fill' => [
'fillType' => 'linear', //線性填充,類似漸變
'rotation' => 45, //漸變角度
'startColor' => [
'rgb' => '34A8E7' //初始顏色
],
//結(jié)束顏色,如果需要單一背景色,請(qǐng)和初始顏色保持一致
'endColor' => [
'argb' => '34A8E7'
]
]
]);
}
列文本格式設(shè)置
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;
... ...
class xxx extends DefaultValueBinder implements FromCollection
... ...
public function bindValue(Cell $cell, $value)
{
$column = $cell->getColumn();
if (in_array($column, ['D', 'E'])) {
$cell->setValueExplicit($value, DataType::TYPE_STRING);
return true;
}
return parent::bindValue($cell, $value);
}
列寬設(shè)置
use Maatwebsite\Excel\Concerns\WithColumnWidths;
... ...
public function columnWidths(): array
{
return [
'A' => 10,
'C' => 10,
'D' => 35,
'H' => 10,
'I' => 10,
'J' => 25,
];
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。