I tried many ways to style my header but nothing worked. I tried each way given in documentation also tried many ways from multiple sites but style now visible in excel sheet. Using this package:"maatwebsite/excel": "^3.1",
This is my code.
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class AccessStatusExport implements FromCollection, WithHeadings, WithStyles
{
protected $contents;
public function __construct($contents)
{
$this->contents = $contents;
}
public function collection()
{
return $this->contents;
}
public function headings(): array
{
return array(
'コンテンツURL',
'タイトル',
'ステータス',
'公開日時',
'テンプレート',
'ファイル種類',
);
}
public function styles(Worksheet $sheet)
{
$sheet->getStyle('A1')->applyFromArray([
'font' => [
'bold' => true,
],
]);
}
}
This is not working because I tried to export in .csv format. As CSV file does not support any style. I you have to style your sheet you should export in .xlxs format.