<?php
session_start();
include("../../../../config/database.php");
$conct  = new connectionCreat();
$conct->connectToDB();
$conct->selectDB();
$setExcelName	   = "excel_dwn".time(); 
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
if (PHP_SAPI == 'cli')
	die('This example should only be run from a Web Browser');
require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
for($col = 'A'; $col !== 'Q'; $col++) {
    $objPHPExcel->getActiveSheet()
        ->getColumnDimension($col)
        ->setAutoSize(true);}
		
$styleArray1 = array(
    'font'  => array(
        'bold'  => true,
        'color' => array('rgb' => 'ff1a1a'),
        'size'  => 16,
		'name'  => 'Cambria'
    ));
$styleArray2 = array(
    'font'  => array(
        'bold'  => true,
        'color' => array('rgb' => '009900'),
        'size'  => 11,
		'name'  => 'Cambria'
    ));	
$styleArray3 = array(
    'font'  => array(
        'bold'  => true,
        'color' => array('rgb' => '3333cc'),
        'size'  => 11,
		'name'  => 'Cambria'
    ));	
$styleArray4 = array(
    'font'  => array(
        'bold'  => true,
        'color' => array('rgb' => '000'),
        'size'  => 11,
		'name'  => 'Cambria'
    ));	
$styleArray5 = array(
    'font'  => array(
        'bold'  => true,
        'color' => array('rgb' => '3333cc'),
        'size'  => 12,
		'name'  => 'Cambria'
    ));
// Set document properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
			 ->setLastModifiedBy("Maarten Balliauw")
			 ->setTitle("Office 2007 XLSX Test Document")
			 ->setSubject("Office 2007 XLSX Test Document")
			 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
			 ->setKeywords("office 2007 openxml php")
			 ->setCategory("Test result file");
// Add some data
$sql		 = mysql_query($_SESSION['excel_page'])or die(mysql_error());
//HEADIGN
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'S NO.')
            ->setCellValue('B1', 'STATE')
			->setCellValue('C1', 'EMPLOYEE NAME')
			->setCellValue('D1', "FATHER'S / HUSBAND NAME")
            ->setCellValue('E1', 'DATE OF BIRTH')
			->setCellValue('F1', 'AADHAR NO')
			->setCellValue('G1', 'MOBILE NO')
			->setCellValue('H1', 'MARITAL STATUS')
			->setCellValue('I1', 'SALARY RATE')
			->setCellValue('J1', 'DA RATE(PER DAY)')
			->setCellValue('K1', 'PHONE RATE(PER MONTH)')
			->setCellValue('L1', 'TA RATE(PER MONTH)')
			->setCellValue('M1', 'TRAVEL EXP(PER MONTH) RATE')
			->setCellValue('N1', 'DATE OF BIRTH')
			->setCellValue('O1', 'EMPLOYEE CODE')
			->setCellValue('P1', 'BANK NAME')
			->setCellValue('Q1', 'BRANCH NAME')
			->setCellValue('R1', 'IFSC CODE')
			->setCellValue('S1', 'ACCOUNT NO')
			->setCellValue('T1', 'UAN NO');									
$objPHPExcel->getActiveSheet()->getStyle('A1:T1')->applyFromArray($styleArray3);								
$i	= 2;	
while( $data1		= mysql_fetch_assoc($sql))
{	
$objPHPExcel->setActiveSheetIndex(0)			
	  ->setCellValue('A'.$i, ($i-1))
	  ->setCellValue('B'.$i, $data1['state'])
	  ->setCellValue('C'.$i, $data1['emp_name'])
	  ->setCellValue('D'.$i, $data1['fname'])				  
	  ->setCellValue('E'.$i, date("Y-m-d",strtotime($data1['dob'])))
	  ->setCellValue('F'.$i, $data1['aadhar_no'])
	  ->setCellValue('G'.$i, $data1['mobil_no'])
	  ->setCellValue('H'.$i, $data1['marital_st'])
	  ->setCellValue('I'.$i, $data1['salary_rate'])
	  ->setCellValue('J'.$i, $data1['da_rate'])
	  ->setCellValue('K'.$i, $data1['phone_rate'])
	  ->setCellValue('L'.$i, $data1['ta_rate'])
	  ->setCellValue('M'.$i, $data1['travel_exp'])
	  ->setCellValue('N'.$i, date("d-m-Y",strtotime($data1['dob'])))
	  ->setCellValue('O'.$i, $data1['emp_code'])
	  
	  ->setCellValue('P'.$i, $data1['bank_name'])
	  ->setCellValue('Q'.$i, $data1['branch_name'])
	  ->setCellValue('R'.$i, $data1['branch_ifsc'])
	  ->setCellValue('S'.$i, $data1['account_no'])
	  ->setCellValue('T'.$i, $data1['uan_no'])
	  
	  ;
	  $objPHPExcel->getActiveSheet()->setCellValueExplicit('F'.$i, $data1['aadhar_no'], PHPExcel_Cell_DataType::TYPE_STRING);
	  $objPHPExcel->getActiveSheet()->setCellValueExplicit('S'.$i, $data1['account_no'], PHPExcel_Cell_DataType::TYPE_STRING);
	  $objPHPExcel->getActiveSheet()->setCellValueExplicit('T'.$i, $data1['uan_no'], PHPExcel_Cell_DataType::TYPE_STRING);
$i++;
}
mysql_close();
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client's web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename='.$setExcelName.".xls");
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;