<?php 
require_once '../vendor/autoload.php';
include "../koneksi.php";

if( !isset( $_GET['id'] ) )
{
	if (!isset( $_GET['qty'] )) {
		header('location:stpj.php');
    	exit();
	}
    header('location:stpj.php');
    exit();
}

$jumlah = $_GET['qty'];
$dok_inc = $_GET['id'];
$inputFileName = 'blanko.xls';

$data = mysqli_query ($koneksi, " select DatePlan from plan 
							where PlanID = $dok_inc");
$row = mysqli_fetch_array ($data);
$phpExcel = PHPExcel_IOFactory::load($inputFileName);

$phpExcel->getProperties()->setCreator('Muhammad Wildan')
		->setTitle('phpSpreadSheet for ProgWeb PPIC')
		->setSubject('Subject PPIC')
		->setDescription('make PHPSpreadsheet');

$phpExcel->getActiveSheet()->setTitle('Form Pengecekan');
		
		for ($i=2; $i <= $jumlah+1; $i++) : 

				$phpExcel->setActiveSheetIndex(0)
					->setCellValue('A'.$i.'', $i-1);

		endfor;

$writer = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="stpj'.$row['DatePlan'].'.xls"');
$writer->save('php://output');

 ?>
