[Operator] Kelengkapan Halaman Dosen
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Support\Legacy\Reports\ReportResult;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
|
||||
@@ -13,19 +14,25 @@ use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use Maatwebsite\Excel\DefaultValueBinder;
|
||||
use Override;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
/**
|
||||
* Hasil laporan operator (kolom + baris ReportResult) sebagai satu lembar Excel: baris kepala tebal dan dibekukan,
|
||||
* lebar kolom mengikuti isi. Teks ditulis apa adanya agar NIP/NIDN panjang dan nol di depan tidak diubah Excel.
|
||||
* lebar kolom mengikuti isi, baris penjumlahan berarsir. Teks ditulis apa adanya agar NIP/NIDN panjang dan nol di depan tidak diubah Excel.
|
||||
*/
|
||||
final class ReportExport extends DefaultValueBinder implements FromArray, ShouldAutoSize, WithCustomValueBinder, WithFreezePane, WithHeadings, WithStrictNullComparison, WithStyles, WithTitle
|
||||
{
|
||||
/** Batas Excel untuk nama lembar. */
|
||||
private const int TITLE_MAX = 31;
|
||||
|
||||
/** Arsir baris penjumlahan: emas lembut, sepadan dengan --color-gold-soft di tabel. */
|
||||
private const string TOTAL_FILL = 'FFF2CC';
|
||||
|
||||
/**
|
||||
* @param list<array{key: string, label: string, num?: bool}> $columns
|
||||
* @param list<array<string, mixed>> $rows
|
||||
@@ -60,9 +67,25 @@ final class ReportExport extends DefaultValueBinder implements FromArray, Should
|
||||
return 'A2';
|
||||
}
|
||||
|
||||
/** Baris kepala tebal; baris penjumlahan (penanda ReportResult::TOTAL_KEY) tebal, berarsir, dan bergaris atas. */
|
||||
public function styles(Worksheet $sheet): array
|
||||
{
|
||||
return [1 => ['font' => ['bold' => true]]];
|
||||
$styles = [1 => ['font' => ['bold' => true]]];
|
||||
$lastColumn = Coordinate::stringFromColumnIndex(max(1, count($this->columns)));
|
||||
|
||||
foreach (array_values($this->rows) as $index => $row) {
|
||||
if ($row[ReportResult::TOTAL_KEY] ?? false) {
|
||||
// Baris 1 = kepala, jadi baris data ke-n ada di baris n + 2; arsir selebar tabel walau sel terakhirnya kosong
|
||||
$n = $index + 2;
|
||||
$styles["A{$n}:{$lastColumn}{$n}"] = [
|
||||
'font' => ['bold' => true],
|
||||
'fill' => ['fillType' => Fill::FILL_SOLID, 'startColor' => ['rgb' => self::TOTAL_FILL]],
|
||||
'borders' => ['top' => ['borderStyle' => Border::BORDER_THIN]],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $styles;
|
||||
}
|
||||
|
||||
/** Teks tetap teks: tidak ditebak sebagai angka (NIP 18 digit, nol di depan) maupun rumus (awalan "="). */
|
||||
|
||||
Reference in New Issue
Block a user