<?php session_start();
include_once ("../../functions/init.php"); 
include_once ($thisUrl."adm1n/functions/access.php");
include_once ($thisUrl."adm1n/functions/koneksi.php");
include_once ($thisUrl."functions/indonesian_date.php");

// Including PHPExcel
require_once('php-excell/Classes/PHPExcel.php');
require_once('php-excell/Classes/PHPExcel.php');

// Including class for the output data in the Excel format
require_once('php-excell/Classes/PHPExcel/Writer/Excel5.php');

// Creating the object of PHPExcel
$xls = new PHPExcel();

// Creating a new connection. Set the $db, $name, $password variables to your connection data
//$db = new PDO('mysql:dbname='.$db.';host = 127.0.0.1', $name, $password);

// Setting the active worksheet index
$xls->setActiveSheetIndex(0);

// Getting the active worksheet
$sheet = $xls->getActiveSheet();

// Setting the title
$sheet->setTitle('My sheet');

// As an example, we will get 10 records from db
//$matrix = $db->prepare("SELECT value FROM excel_test LIMIT 10");
//$matrix->execute();
//$matrix = $matrix->fetchAll(PDO::FETCH_ASSOC);
// Method setCellValueByColumnAndRow() of worksheet class allows us to set the value of cell referencing to it by the row and column number.
/** 
$i = 1;
$j = 1;
foreach($matrix as $mat) {
       $sheet->setCellValueByColumnAndRow($i, $j, $mat['value']);
       $j++;
}
**/
//Preparing headers
 header ( "Expires: Mon, 1 Apr 1974 05:00:00 GMT" );
 header ( "Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT" );
 header ( "Cache-Control: no-cache, must-revalidate" );
 header ( "Pragma: no-cache" );
 header ( "Content-type: application/vnd.ms-excel" );
 header ( "Content-Disposition: attachment; filename=matrix.xls" );

//Receiving a new excel file!
 $objWriter = new PHPExcel_Writer_Excel5($xls);
 $objWriter->save('php://output');?>