<?php
require "../../config/koneksi.php";
require "../../vendor/autoload.php";
require("../../config/function.php");

use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;

$kelas=$_GET['kelas'];
$mapel=$_GET['mapel'];

 

$spreadsheet = new Spreadsheet();
$spreadsheet->getProperties()->setCreator('Edi Sukarna')
->setLastModifiedBy('Edi Sukarna')
->setTitle('Office 2007 XLSX')
->setSubject('Office 2007 XLSX')
->setDescription('Test document for Office 2007 XLSX.')
->setKeywords('office 2007 openxml php')
->setCategory('Test result file');

$spreadsheet->getActiveSheet()->getStyle('A4:Y4')
    ->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_WHITE);

    $spreadsheet->getActiveSheet()->getStyle('A4:Y4')->getFill()
    ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
    ->getStartColor()->setARGB('FFFF0000');

$spreadsheet->setActiveSheetIndex(0)
->setCellValue('E1', "INFORMASI")
->setCellValue('E2', "Isikan Nilai Pada TP sesuai Jumlah TP pada menu Tujuan Pembelajaran")
->setCellValue('E3', "Pada TP masing-masing siswa harus ada nilai tertinggi dan terendah, Misal TP1 72, TP2 72, TP3 70, TP4 73")
;
$spreadsheet->setActiveSheetIndex(0)
->setCellValue('A4', "No")
->setCellValue('B4', "ID")
->setCellValue('C4', "Kelas")
->setCellValue('D4', "Mapel") 
->setCellValue('E4', "Nama Siswa")
->setCellValue('F4', "TP1")
->setCellValue('G4', "TP2")
->setCellValue('H4', "TP3")
->setCellValue('I4', "TP4")
->setCellValue('J4', "TP5")
->setCellValue('K4', "TP6")
->setCellValue('L4', "TP7")
->setCellValue('M4', "TP8")
->setCellValue('N4', "TP9")
->setCellValue('O4', "TP10")
->setCellValue('P4', "TP11")
->setCellValue('Q4', "TP12")
->setCellValue('R4', "TP13")
->setCellValue('S4', "TP14")
->setCellValue('T4', "TP15")
->setCellValue('U4', "TP16")
->setCellValue('V4', "TP17")
->setCellValue('W4', "TP18")
->setCellValue('X4', "TP19")
->setCellValue('Y4', "TP20");


$i=5; 
$no=1; 
$sql = mysqli_query($koneksi, "SELECT * FROM siswa WHERE id_kelas='$kelas' ");
while($row = mysqli_fetch_array($sql)){ 
$spreadsheet->setActiveSheetIndex(0)
	->setCellValue('A'.$i, $no)
	->setCellValue('B'.$i, $row['id_siswa'])
	->setCellValue('C'.$i, $row['id_kelas'])
	->setCellValue('D'.$i, $mapel)
	->setCellValue('E'.$i, $row['nama'])
	->setCellValue('F'.$i, "")
	->setCellValue('G'.$i, "")
	->setCellValue('H'.$i, "")
	->setCellValue('I'.$i, "")
	->setCellValue('J'.$i, "")
	->setCellValue('K'.$i, "")
	->setCellValue('L'.$i, "")
	->setCellValue('M'.$i, "")
	->setCellValue('N'.$i, "")
	->setCellValue('O'.$i, "")
	->setCellValue('P'.$i, "")
	->setCellValue('Q'.$i, "")
	->setCellValue('R'.$i, "")
	->setCellValue('S'.$i, "")
	->setCellValue('T'.$i, "")
	->setCellValue('U'.$i, "")
	->setCellValue('V'.$i, "")
	->setCellValue('W'.$i, "")
	->setCellValue('X'.$i, "")
	->setCellValue('Y'.$i, "")
		;
	
	$i++; $no++;
}

$spreadsheet->getActiveSheet()->getColumnDimension('A')->setWidth(5); 
$spreadsheet->getActiveSheet()->getColumnDimension('B')->setWidth(0); 
$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(0); 
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(0); 
$spreadsheet->getActiveSheet()->getColumnDimension('E')->setWidth(35); 
$spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(5);
$spreadsheet->getActiveSheet()->getColumnDimension('G')->setWidth(5); 
$spreadsheet->getActiveSheet()->getColumnDimension('H')->setWidth(5);
$spreadsheet->getActiveSheet()->getColumnDimension('I')->setWidth(5); 
$spreadsheet->getActiveSheet()->getColumnDimension('J')->setWidth(5);
$spreadsheet->getActiveSheet()->getColumnDimension('K')->setWidth(5); 
$spreadsheet->getActiveSheet()->getColumnDimension('L')->setWidth(5);
$spreadsheet->getActiveSheet()->getColumnDimension('M')->setWidth(5); 
$spreadsheet->getActiveSheet()->getColumnDimension('N')->setWidth(5);
$spreadsheet->getActiveSheet()->getColumnDimension('O')->setWidth(5);
$spreadsheet->getActiveSheet()->getColumnDimension('P')->setWidth(5);
$spreadsheet->getActiveSheet()->getColumnDimension('Q')->setWidth(5); 
$spreadsheet->getActiveSheet()->getColumnDimension('R')->setWidth(5);
$spreadsheet->getActiveSheet()->getColumnDimension('S')->setWidth(5); 
$spreadsheet->getActiveSheet()->getColumnDimension('T')->setWidth(5);
$spreadsheet->getActiveSheet()->getColumnDimension('U')->setWidth(5); 
$spreadsheet->getActiveSheet()->getColumnDimension('V')->setWidth(5);
$spreadsheet->getActiveSheet()->getColumnDimension('W')->setWidth(5);
$spreadsheet->getActiveSheet()->getColumnDimension('X')->setWidth(5);
$spreadsheet->getActiveSheet()->getColumnDimension('Y')->setWidth(5);
$spreadsheet->getActiveSheet()->setTitle('Formatif-'.$mapel);

$spreadsheet->setActiveSheetIndex(0);


header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

header("Content-Disposition: attachment; filename=Format Nilai Formatif Kelas $kelas Mapel $mapel.xlsx");
header('Cache-Control: max-age=0');

header('Cache-Control: max-age=1');


header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); 
header('Cache-Control: cache, must-revalidate'); 
header('Pragma: public');

$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');

?>
