[Operator] Kelengkapan menu Browse Kurikulum
This commit is contained in:
@@ -4,7 +4,7 @@ namespace App\Exports;
|
||||
|
||||
use App\Support\Legacy\Reports\ReportResult;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnWidths;
|
||||
use Maatwebsite\Excel\Concerns\WithCustomValueBinder;
|
||||
use Maatwebsite\Excel\Concerns\WithFreezePane;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
@@ -25,11 +25,14 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
* Hasil laporan operator (kolom + baris ReportResult) sebagai satu lembar Excel: baris kepala tebal dan dibekukan,
|
||||
* 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
|
||||
final class ReportExport extends DefaultValueBinder implements FromArray, WithColumnWidths, WithCustomValueBinder, WithFreezePane, WithHeadings, WithStrictNullComparison, WithStyles, WithTitle
|
||||
{
|
||||
/** Batas Excel untuk nama lembar. */
|
||||
private const int TITLE_MAX = 31;
|
||||
|
||||
/** Baris pertama yang dipakai menaksir lebar kolom (lebar otomatis PhpSpreadsheet lambat pada laporan puluhan ribu baris). */
|
||||
private const int WIDTH_SAMPLE = 1000;
|
||||
|
||||
/** Arsir baris penjumlahan: emas lembut, sepadan dengan --color-gold-soft di tabel. */
|
||||
private const string TOTAL_FILL = 'FFF2CC';
|
||||
|
||||
@@ -67,6 +70,30 @@ final class ReportExport extends DefaultValueBinder implements FromArray, Should
|
||||
return 'A2';
|
||||
}
|
||||
|
||||
/**
|
||||
* Lebar kolom (satuan karakter) dari judul dan baris-baris pertama, dibatasi 8 sampai 60.
|
||||
*
|
||||
* @return array<string, float>
|
||||
*/
|
||||
public function columnWidths(): array
|
||||
{
|
||||
$sample = array_slice($this->rows, 0, self::WIDTH_SAMPLE);
|
||||
$widths = [];
|
||||
|
||||
foreach (array_values($this->columns) as $index => $column) {
|
||||
$longest = mb_strlen((string) $column['label']);
|
||||
foreach ($sample as $row) {
|
||||
$value = $row[$column['key']] ?? null;
|
||||
if (is_scalar($value)) {
|
||||
$longest = max($longest, mb_strlen((string) $value));
|
||||
}
|
||||
}
|
||||
$widths[Coordinate::stringFromColumnIndex($index + 1)] = (float) min(60, max(8, $longest + 3));
|
||||
}
|
||||
|
||||
return $widths;
|
||||
}
|
||||
|
||||
/** Baris kepala tebal; baris penjumlahan (penanda ReportResult::TOTAL_KEY) tebal, berarsir, dan bergaris atas. */
|
||||
public function styles(Worksheet $sheet): array
|
||||
{
|
||||
@@ -94,8 +121,11 @@ final class ReportExport extends DefaultValueBinder implements FromArray, Should
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$cell->setValueExplicit(StringHelper::sanitizeUTF8($value), DataType::TYPE_STRING);
|
||||
// Tanpa segitiga peringatan "angka disimpan sebagai teks" di Excel
|
||||
$cell->getIgnoredErrors()->setNumberStoredAsText(is_numeric($value));
|
||||
// Tanpa segitiga peringatan "angka disimpan sebagai teks" di Excel; hanya untuk teks berupa angka agar
|
||||
// tidak membuat objek tambahan di setiap sel (laporan besar cepat menghabiskan memori)
|
||||
if (is_numeric($value)) {
|
||||
$cell->getIgnoredErrors()->setNumberStoredAsText(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user