<?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;

  $ms=mysqli_fetch_array($edit2);
  $mapel=$ms['kode'];


$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->setActiveSheetIndex(0)
->setCellValue('A1', "No")
->setCellValue('B1', "NIS")
->setCellValue('C1', "NAMA")
->setCellValue('D1', "KELAS") 
->setCellValue('E1', "TEMPAT LAHIR")
->setCellValue('F1', "TANGGAL LAHIR")
->setCellValue('G1', "ALAMAT")
->setCellValue('H1', "NAMA AYAH") 
->setCellValue('I1', "NAMA IBU") 
->setCellValue('J1', "PEKERJAAN AYAH")
->setCellValue('K1', "PEKERJAAN IBU")
->setCellValue('L1', "ALAMAT ORTU")
->setCellValue('M1', "DESA")
->setCellValue('N1', "KECAMATAN")
->setCellValue('O1', "KABUPATEN")
->setCellValue('P1', "PROPINSI")
->setCellValue('Q1', "WALI")
->setCellValue('R1', "PEKERJAAN WALI")
->setCellValue('S1', "ALAMAT WALI")
; 

$i=2; 
$no=1; 
$sql = mysqli_query($koneksi, "SELECT * FROM siswa");

while($row = mysqli_fetch_array($sql)){ 
$spreadsheet->setActiveSheetIndex(0)
	->setCellValue('A'.$i, $no)
	->setCellValue('B'.$i, $row['nis'])
	->setCellValue('C'.$i, $row['nama'])
	->setCellValue('D'.$i, $row['id_kelas'])
	->setCellValue('E'.$i, '')
	->setCellValue('F'.$i, 'Contoh 12 Juli 2019')
	->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, '')
	;
	
	$i++; $no++;
}

$spreadsheet->getActiveSheet()->getColumnDimension('A')->setWidth(5); 
$spreadsheet->getActiveSheet()->getColumnDimension('B')->setWidth(12); 
$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(30); 
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10); 
$spreadsheet->getActiveSheet()->getColumnDimension('E')->setWidth(18); 
$spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('G')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('H')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('I')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('J')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('K')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('L')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('M')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('N')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('O')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('P')->setWidth(20); 
$spreadsheet->getActiveSheet()->getColumnDimension('Q')->setWidth(20);
$spreadsheet->getActiveSheet()->getColumnDimension('R')->setWidth(20);
$spreadsheet->getActiveSheet()->getColumnDimension('S')->setWidth(20);

$spreadsheet->getActiveSheet()->setTitle('DATA_SISWA');

$spreadsheet->setActiveSheetIndex(0);


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

header("Content-Disposition: attachment; filename=UPDATE SISWA.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');

?>
