60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use Maatwebsite\Excel\Concerns\FromArray;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\WithStyles;
|
|
use PhpOffice\PhpSpreadsheet\Style\Border;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
|
|
class DashboardExport implements FromArray, WithStyles
|
|
{
|
|
protected $data;
|
|
|
|
public function __construct($data)
|
|
{
|
|
$this->data = $data;
|
|
}
|
|
/**
|
|
* @return \Illuminate\Support\Collection
|
|
*/
|
|
public function array(): array
|
|
{
|
|
return $this->data;
|
|
}
|
|
|
|
public function styles(Worksheet $sheet)
|
|
{
|
|
// Hitung jumlah row yang dihasilkan
|
|
$lastRow = $sheet->getHighestRow();
|
|
$lastColumn = $sheet->getHighestColumn();
|
|
|
|
// Range seluruh data, misal A1:C20
|
|
$range = 'A1:' . $lastColumn . $lastRow;
|
|
|
|
// Terapkan border
|
|
$sheet->getStyle($range)->applyFromArray([
|
|
'borders' => [
|
|
'allBorders' => [
|
|
'borderStyle' => Border::BORDER_THIN,
|
|
'color' => ['rgb' => '000000'], // warna hitam
|
|
],
|
|
],
|
|
]);
|
|
|
|
// Optional: header kuning + bold
|
|
$sheet->getStyle('A1:' . $lastColumn . '1')->applyFromArray([
|
|
'font' => [
|
|
'bold' => true,
|
|
],
|
|
'fill' => [
|
|
'fillType' => 'solid',
|
|
'color' => ['rgb' => 'FFFF00'], // header kuning
|
|
],
|
|
]);
|
|
|
|
return [];
|
|
}
|
|
}
|