<?php
ini_set('display_errors', 1);

require_once $base_path_to_learning . "vendor/autoload.php";

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;


function marksheet_gazette_report_template32(array $data)
{
    ob_start();

    $spreadsheet = new Spreadsheet();
    $spreadsheet->removeSheetByIndex(0);

    $sheet1 = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, 'TERM-I');
    $spreadsheet->addSheet($sheet1, 0);
    generate_template32_term1_gazette($sheet1, $data);

    $sheet2 = new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet($spreadsheet, 'TERM-II');
    $spreadsheet->addSheet($sheet2, 1);
    generate_template32_term2_gazette($sheet2, $data);

    $spreadsheet->setActiveSheetIndex(0);

    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="marksheet_gazette.xlsx"');
    header('Cache-Control: max-age=0');

    ob_end_clean();
    (new Xlsx($spreadsheet))->save('php://output');
    exit;
}

function t32_border()
{
    return ['allBorders' => ['borderStyle' => Border::BORDER_THIN]];
}

function t32_header_style()
{
    return [
        'font' => ['bold' => true],
        'alignment' => [
            'horizontal' => Alignment::HORIZONTAL_CENTER,
            'vertical'   => Alignment::VERTICAL_CENTER
        ],
        'borders' => t32_border(),
        'fill' => [
            'fillType' => Fill::FILL_SOLID,
            'startColor' => ['argb' => 'FFEFEFEF']
        ]
    ];
}

function t32_cell_style()
{
    return [
        'alignment' => [
            'horizontal' => Alignment::HORIZONTAL_CENTER,
            'vertical'   => Alignment::VERTICAL_CENTER
        ],
        'borders' => t32_border()
    ];
}

function generate_template32_term1_gazette($sheet, $data)
{
    if (empty($data)) return;

    /* ================= STYLES ================= */
    $titleStyle = [
        'font' => ['bold' => true, 'size' => 13],
        'alignment' => [
            'horizontal' => Alignment::HORIZONTAL_CENTER,
            'vertical'   => Alignment::VERTICAL_CENTER
        ]
    ];

    $headerStyle = [
        'font' => ['bold' => true, 'size' => 10],
        'alignment' => [
            'horizontal' => Alignment::HORIZONTAL_CENTER,
            'vertical'   => Alignment::VERTICAL_CENTER,
            'wrapText'   => true
        ],
        'borders' => ['allBorders' => ['borderStyle' => Border::BORDER_THIN]],
        'fill' => [
            'fillType' => Fill::FILL_SOLID,
            'startColor' => ['argb' => 'FFEFEFEF']
        ]
    ];

    $cellStyle = [
        'alignment' => [
            'horizontal' => Alignment::HORIZONTAL_CENTER,
            'vertical'   => Alignment::VERTICAL_CENTER
        ],
        'borders' => ['allBorders' => ['borderStyle' => Border::BORDER_THIN]]
    ];

    /* ================= COLUMN WIDTH ================= */
    $sheet->getColumnDimension('A')->setWidth(6);
    $sheet->getColumnDimension('B')->setWidth(12);
    $sheet->getColumnDimension('C')->setWidth(25);

    for ($i = 4; $i <= 60; $i++) {
        $sheet->getColumnDimension(
            Coordinate::stringFromColumnIndex($i)
        )->setWidth(10);
    }

    /* ================= TITLES ================= */
    $sheet->setCellValue(
        'A1',
        $data[0]['institution_info']['institution_name'] . ' , ' .
            $data[0]['branch_info']['name']
    );
    $sheet->setCellValue(
        'A2',
        $data[0]['examination_name'] . ' (' . $data[0]['academic_session'] . ')'
    );
    $sheet->setCellValue(
        'A3',
        'CLASS : ' . $data[0]['class_name'] . ' - SECTION : ' . $data[0]['section_name']
    );

    /* ================= HEADERS ================= */
    $rowMain = 5;
    $rowSub  = 6;
    $rowOW = 7;

    // Fixed columns
    $sheet->setCellValue('A5', 'R. NO');
    $sheet->setCellValue('B5', 'ADM. NO');
    $sheet->setCellValue('C5', 'NAME OF THE STUDENT');
    $sheet->mergeCells('A5:A6');
    $sheet->mergeCells('B5:B6');
    $sheet->mergeCells('C5:C6');

    $col = 4;

    /* ---- 4 COLUMN SUBJECTS ---- */
    $subjects4 = ['ENGLISH', 'HINDI', 'MATHS'];
    $sub4 = ['PERIODIC 1', 'PERIODIC 1', 'PERIODIC 2', 'PERIODIC 2'];

    foreach ($subjects4 as $subject) {
        $start = $col;
        foreach ($sub4 as $s) {
            $sheet->setCellValue(
                Coordinate::stringFromColumnIndex($col++) . $rowSub,
                $s
            );
        }
        $sheet->mergeCells(
            Coordinate::stringFromColumnIndex($start) . $rowMain . ':' .
                Coordinate::stringFromColumnIndex($col - 1) . $rowMain
        );
        $sheet->setCellValue(
            Coordinate::stringFromColumnIndex($start) . $rowMain,
            $subject
        );
    }

    /* ---- 2 COLUMN SUBJECTS ---- */
    $subjects2 = ['EVS (ORAL)', 'GK & RHYMES', 'DRAWING'];
    $sub2 = ['PERIODIC 1', 'PERIODIC 2'];

    foreach ($subjects2 as $subject) {
        $start = $col;
        foreach ($sub2 as $s) {
            $sheet->setCellValue(
                Coordinate::stringFromColumnIndex($col++) . $rowSub,
                $s
            );
        }
        $sheet->mergeCells(
            Coordinate::stringFromColumnIndex($start) . $rowMain . ':' .
                Coordinate::stringFromColumnIndex($col - 1) . $rowMain
        );
        $sheet->setCellValue(
            Coordinate::stringFromColumnIndex($start) . $rowMain,
            $subject
        );
    }

    /* ---- OVERALL (2) ---- */
    $start = $col;
    foreach (['PERIODIC 1', 'PERIODIC 2'] as $o) {
        $sheet->setCellValue(
            Coordinate::stringFromColumnIndex($col++) . $rowSub,
            $o
        );
    }
    $sheet->mergeCells(
        Coordinate::stringFromColumnIndex($start) . $rowMain . ':' .
            Coordinate::stringFromColumnIndex($col - 1) . $rowMain
    );
    $sheet->setCellValue(
        Coordinate::stringFromColumnIndex($start) . $rowMain,
        'OVERALL'
    );

    /* ---- HEALTH STATUS (3) ---- */
    $start = $col;
    foreach (['HEIGHT', 'WEIGHT', 'BLOOD GROUP'] as $h) {
        $sheet->setCellValue(
            Coordinate::stringFromColumnIndex($col++) . $rowSub,
            $h
        );
    }
    $sheet->mergeCells(
        Coordinate::stringFromColumnIndex($start) . $rowMain . ':' .
            Coordinate::stringFromColumnIndex($col - 1) . $rowMain
    );
    $sheet->setCellValue(
        Coordinate::stringFromColumnIndex($start) . $rowMain,
        'HEALTH STATUS'
    );

    /* ---- ATTENDANCE (3) ---- */
    $start = $col;
    foreach (['TERM-I', 'TERM-II', 'TOTAL'] as $a) {
        $sheet->setCellValue(
            Coordinate::stringFromColumnIndex($col++) . $rowSub,
            $a
        );
    }
    $sheet->mergeCells(
        Coordinate::stringFromColumnIndex($start) . $rowMain . ':' .
            Coordinate::stringFromColumnIndex($col - 1) . $rowMain
    );
    $sheet->setCellValue(
        Coordinate::stringFromColumnIndex($start) . $rowMain,
        'ATTENDANCE'
    );

    /* ---- FINAL COLUMNS ---- */
    foreach (['COMPETITION', "CLASS TEACHER'S REMARKS"] as $last) {
        $sheet->mergeCells(
            Coordinate::stringFromColumnIndex($col) . $rowMain . ':' .
                Coordinate::stringFromColumnIndex($col) . $rowSub
        );
        $sheet->setCellValue(
            Coordinate::stringFromColumnIndex($col++) . $rowMain,
            $last
        );
    }

    $lastCol = Coordinate::stringFromColumnIndex($col - 1);

    $rowOW = 7;     // new row for O/W
    $colOW = 4;     // starts from column D (English)

    for ($i = 0; $i < 3; $i++) {
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($colOW++) . $rowOW, 'ORAL');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($colOW++) . $rowOW, 'WRITTEN');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($colOW++) . $rowOW, 'ORAL');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($colOW++) . $rowOW, 'WRITTEN');
    }

    // Style O/W row
    $sheet->getStyle(
        Coordinate::stringFromColumnIndex(4) . $rowOW . ':' .
            Coordinate::stringFromColumnIndex($colOW - 1) . $rowOW
    )->applyFromArray($headerStyle);


    /* ================= STYLING ================= */
    $sheet->mergeCells("A1:{$lastCol}1");
    $sheet->mergeCells("A2:{$lastCol}2");
    $sheet->mergeCells("A3:{$lastCol}3");

    $sheet->getStyle("A1:A3")->applyFromArray($titleStyle);
    $sheet->getStyle("A5:{$lastCol}6")->applyFromArray($headerStyle);

    $sheet->getRowDimension(5)->setRowHeight(35);
    $sheet->getRowDimension(6)->setRowHeight(40);

    /* ================= DATA ================= */
    $row = 8;
    foreach ($data as $i => $student) {

        $marks = json_decode($student['data'], true) ?? [];
        $col = 1;

        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $i + 1);
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $student['admission_number']);
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $student['student_name']);

        // ENGLISH
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[39]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[41]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[40]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[42]  ?? '');

        // HINDI
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[43]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[45]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[44]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[46]  ?? '');

        // MATHS
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[47]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[49] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[48] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[50] ?? '');

        // EVS
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[51] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[52] ?? '');

        // GK & RHYMES
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[53] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[54] ?? '');

        // DRAWING
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[55] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[56] ?? '');

        // OVERALL
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[57] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[58] ?? '');

        // HEALTH STATUS
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[59] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[60] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[61] ?? '');

        // ATTENDANCE
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, ($marks[65] ?? '') . '/' . ($marks[62] ?? ''));
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, ($marks[66] ?? '') . '/' . ($marks[63] ?? ''));
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, ($marks[67] ?? '') . '/' . ($marks[64] ?? ''));

        // FINAL
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, ($marks[71] ?? '') . ', ' . ($marks[72] ?? ''));
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[73] ?? '');


        $sheet->getStyle("A{$row}:{$lastCol}{$row}")->applyFromArray($cellStyle);
        $row++;
    }
}

function generate_template32_term2_gazette($sheet, $data)
{
    if (empty($data)) return;

    /* ================= STYLES ================= */
    $titleStyle = [
        'font' => ['bold' => true, 'size' => 13],
        'alignment' => [
            'horizontal' => Alignment::HORIZONTAL_CENTER,
            'vertical'   => Alignment::VERTICAL_CENTER
        ]
    ];

    $headerStyle = [
        'font' => ['bold' => true, 'size' => 10],
        'alignment' => [
            'horizontal' => Alignment::HORIZONTAL_CENTER,
            'vertical'   => Alignment::VERTICAL_CENTER,
            'wrapText'   => true
        ],
        'borders' => ['allBorders' => ['borderStyle' => Border::BORDER_THIN]],
        'fill' => [
            'fillType' => Fill::FILL_SOLID,
            'startColor' => ['argb' => 'FFEFEFEF']
        ]
    ];

    $cellStyle = [
        'alignment' => [
            'horizontal' => Alignment::HORIZONTAL_CENTER,
            'vertical'   => Alignment::VERTICAL_CENTER
        ],
        'borders' => ['allBorders' => ['borderStyle' => Border::BORDER_THIN]]
    ];

    /* ================= COLUMN WIDTH ================= */
    $sheet->getColumnDimension('A')->setWidth(6);
    $sheet->getColumnDimension('B')->setWidth(12);
    $sheet->getColumnDimension('C')->setWidth(25);

    for ($i = 4; $i <= 60; $i++) {
        $sheet->getColumnDimension(
            Coordinate::stringFromColumnIndex($i)
        )->setWidth(10);
    }

    /* ================= TITLES ================= */
    $sheet->setCellValue(
        'A1',
        $data[0]['institution_info']['institution_name'] . ' , ' .
            $data[0]['branch_info']['name']
    );
    $sheet->setCellValue(
        'A2',
        $data[0]['examination_name'] . ' (' . $data[0]['academic_session'] . ')'
    );
    $sheet->setCellValue(
        'A3',
        'CLASS : ' . $data[0]['class_name'] . ' - SECTION : ' . $data[0]['section_name']
    );

    /* ================= HEADERS ================= */
    $rowMain = 5;
    $rowSub  = 6;
    $rowOW = 7;

    // Fixed columns
    $sheet->setCellValue('A5', 'R. NO');
    $sheet->setCellValue('B5', 'ADM. NO');
    $sheet->setCellValue('C5', 'NAME OF THE STUDENT');
    $sheet->mergeCells('A5:A6');
    $sheet->mergeCells('B5:B6');
    $sheet->mergeCells('C5:C6');

    $col = 4;

    /* ---- 4 COLUMN SUBJECTS ---- */
    $subjects4 = ['ENGLISH', 'HINDI', 'MATHS'];
    $sub4 = ['PERIODIC 1', 'PERIODIC 1', 'PERIODIC 2', 'PERIODIC 2'];

    foreach ($subjects4 as $subject) {
        $start = $col;
        foreach ($sub4 as $s) {
            $sheet->setCellValue(
                Coordinate::stringFromColumnIndex($col++) . $rowSub,
                $s
            );
        }
        $sheet->mergeCells(
            Coordinate::stringFromColumnIndex($start) . $rowMain . ':' .
                Coordinate::stringFromColumnIndex($col - 1) . $rowMain
        );
        $sheet->setCellValue(
            Coordinate::stringFromColumnIndex($start) . $rowMain,
            $subject
        );
    }

    /* ---- 2 COLUMN SUBJECTS ---- */
    $subjects2 = ['EVS (ORAL)', 'GK & RHYMES', 'DRAWING'];
    $sub2 = ['PERIODIC 1', 'PERIODIC 2'];

    foreach ($subjects2 as $subject) {
        $start = $col;
        foreach ($sub2 as $s) {
            $sheet->setCellValue(
                Coordinate::stringFromColumnIndex($col++) . $rowSub,
                $s
            );
        }
        $sheet->mergeCells(
            Coordinate::stringFromColumnIndex($start) . $rowMain . ':' .
                Coordinate::stringFromColumnIndex($col - 1) . $rowMain
        );
        $sheet->setCellValue(
            Coordinate::stringFromColumnIndex($start) . $rowMain,
            $subject
        );
    }

    /* ---- OVERALL (2) ---- */
    $start = $col;
    foreach (['PERIODIC 1', 'PERIODIC 2'] as $o) {
        $sheet->setCellValue(
            Coordinate::stringFromColumnIndex($col++) . $rowSub,
            $o
        );
    }
    $sheet->mergeCells(
        Coordinate::stringFromColumnIndex($start) . $rowMain . ':' .
            Coordinate::stringFromColumnIndex($col - 1) . $rowMain
    );
    $sheet->setCellValue(
        Coordinate::stringFromColumnIndex($start) . $rowMain,
        'OVERALL'
    );

    $psStart = $col;
    foreach (['UNIFORM', 'CIRCULAR FOLLOW UP', 'HOMEWORK/ACT.SUBMISSION', 'PTM/ATTENDANCE'] as $ps) {
        $sheet->mergeCells(
            Coordinate::stringFromColumnIndex($col) . $rowSub . ':' .
                Coordinate::stringFromColumnIndex($col + 1) . $rowSub
        );
        $sheet->setCellValue(
            Coordinate::stringFromColumnIndex($col) . $rowSub,
            $ps
        );
        $sheet->getRowDimension(5)->setRowHeight(35);
        $sheet->getRowDimension(6)->setRowHeight(45);
        $col += 2;
    }
    $sheet->mergeCells(
        Coordinate::stringFromColumnIndex($psStart) . $rowMain . ':' .
            Coordinate::stringFromColumnIndex($col - 1) . $rowMain
    );
    $sheet->setCellValue(
        Coordinate::stringFromColumnIndex($psStart) . $rowMain,
        'PARENTAL SUPPORT'
    );

    $taStart = $col;
    foreach (['PERSONAL HYGIENE', 'PUNCTUALITY', 'VALUE SYSTEM', 'SELF-CONFIDENCE'] as $ta) {
        $sheet->mergeCells(
            Coordinate::stringFromColumnIndex($col) . $rowSub . ':' .
                Coordinate::stringFromColumnIndex($col + 1) . $rowSub
        );
        $sheet->setCellValue(
            Coordinate::stringFromColumnIndex($col) . $rowSub,
            $ta
        );
        $sheet->getRowDimension(5)->setRowHeight(35);
        $sheet->getRowDimension(6)->setRowHeight(45);
        $col += 2;
    }
    $sheet->mergeCells(
        Coordinate::stringFromColumnIndex($taStart) . $rowMain . ':' .
            Coordinate::stringFromColumnIndex($col - 1) . $rowMain
    );
    $sheet->setCellValue(
        Coordinate::stringFromColumnIndex($taStart) . $rowMain,
        'TEACHERS ASSESSMENT'
    );

    foreach (['CLASS TEACHER REMARKS', 'PROMOTED TO CLASS'] as $last) {
        $sheet->mergeCells(
            Coordinate::stringFromColumnIndex($col) . $rowMain . ':' .
                Coordinate::stringFromColumnIndex($col) . $rowSub
        );
        $sheet->setCellValue(
            Coordinate::stringFromColumnIndex($col++) . $rowMain,
            $last
        );
    }

    $lastCol = Coordinate::stringFromColumnIndex($col - 1);

    $rowOW = 7;     // new row for O/W
    $colOW = 4;     // starts from column D (English)

    for ($i = 0; $i < 3; $i++) {
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($colOW++) . $rowOW, 'ORAL');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($colOW++) . $rowOW, 'WRITTEN');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($colOW++) . $rowOW, 'ORAL');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($colOW++) . $rowOW, 'WRITTEN');
    }

    // Style O/W row
    $sheet->getStyle(
        Coordinate::stringFromColumnIndex(4) . $rowOW . ':' .
            Coordinate::stringFromColumnIndex($colOW - 1) . $rowOW
    )->applyFromArray($headerStyle);


    /* ================= STYLING ================= */
    $sheet->mergeCells("A1:{$lastCol}1");
    $sheet->mergeCells("A2:{$lastCol}2");
    $sheet->mergeCells("A3:{$lastCol}3");

    $sheet->getStyle("A1:A3")->applyFromArray($titleStyle);
    $sheet->getStyle("A5:{$lastCol}6")->applyFromArray($headerStyle);

    $sheet->getRowDimension(5)->setRowHeight(35);
    $sheet->getRowDimension(6)->setRowHeight(40);

    /* ================= DATA ================= */
    $row = 8;
    foreach ($data as $i => $student) {

        $marks = json_decode($student['data'], true) ?? [];
        $col = 1;

        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $i + 1);
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $student['admission_number']);
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $student['student_name']);

        // ENGLISH
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[1]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[3]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[2]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[4]  ?? '');

        // HINDI
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[5]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[7]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[6]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[8]  ?? '');

        // MATHS
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[9]  ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[11] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[10] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[12] ?? '');

        // EVS
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[13] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[14] ?? '');

        // GK & RHYMES
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[15] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[16] ?? '');

        // DRAWING
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[17] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[18] ?? '');

        // OVERALL
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[19] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[20] ?? '');

        // PARENTAL SUPPORT
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[21] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[22] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[23] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[24] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[25] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[26] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[27] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[28] ?? '');

        // TEACHERS ASSESSMENT
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[29] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[30] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[31] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[32] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[33] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[34] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[35] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[36] ?? '');

        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[37] ?? '');
        $sheet->setCellValue(Coordinate::stringFromColumnIndex($col++) . $row, $marks[38] ?? '');

        $sheet->getStyle("A{$row}:{$lastCol}{$row}")->applyFromArray($cellStyle);
        $row++;
    }
}
