<?php
	include 'PhpExcel/PHPExcel.php' ;

	$page_filename = $page_export_file_name.date( 'Ymd', time() ) ;

    $objPHPExcel   = new PHPExcel() ;
    $objPHPExcel->getProperties()
                ->setCreator(COMPANY)
                ->setTitle(COMPANY)
                ->setSubject(COMPANY)
                ->setDescription(COMPANY)
                ->setKeywords(COMPANY)
                ->setCategory(COMPANY) ;

    $objPHPExcel->getActiveSheet()->setTitle( $page_filename ) ;
    $objPHPExcel->setActiveSheetIndex(0);
    $objWriter   = PHPExcel_IOFactory::createWriter( $objPHPExcel, 'Excel5' ) ;

    // default parameter
    $count       = 1 ;
    $char        = 'A' ;


    if ($t_title_header_excel != '') {
        $newChar     = $char ;
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($newChar.$count, $t_title_header_excel);
        $count ++ ;
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue($newChar.$count, '');
        $count ++;
    }

    $newChar     = $char ;
    foreach( $array_header_excel as $k => $v ){
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue( $newChar.$count, $v ) ;
        $newChar++ ;
    }
    $count++ ;

	$redeem_q = $mysqli->query( $mysqli_query ) ;
	if (!empty($array_body_excel)){
	    foreach( $array_body_excel as $kk => $vv ){
	    	$newChar     = $char ;
	    	foreach( $vv as $kkk => $vvv ){
	            $objPHPExcel->setActiveSheetIndex(0)->setCellValue( $newChar.$count, $vvv ) ;
	            $newChar++ ;
	        }
	        $count++ ;
	    }
	}
	
    header( 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' ) ; 
    header( 'Content-Disposition: attachment;filename="'.$page_filename.'.xls"' ) ;
    header( 'Cache-Control: max-age=0' ) ;
    // save to pc
    ob_clean();
    $objWriter->save('php://output') ;
    header( "Refresh: 0" ) ;
	exit ;
?>